Wednesday, April 16, 2008

Adding a Column to JSON using Coldfusion8

I use Spry to output a lot of queries that I use in my projects.

So I call my coldfusion function from Spry


var ts = new Date();
var spry_ContactList = new
Spry.Data.JSONDataSet("module_contacts.cfc?method=qry_ContactsList &returnFormat=json& queryFormat=column&TS=" + ts.toString(),{path:"DATA", pathIsObjectOfArrays:true});


There are a couple of things to note here, first of I am using Coldfusion 8's new returnFormat=json to return the query that resides in my function, as well as this I am also using queryFormat=column. Finally I have added on a date string to prevent browsers such as IE6 from caching the request.

So based on the above I can return my query as JSON, however I found that any dates were being returned in a fairly ugly way eg. March 21, 2008 00:00:00. I wanted to remove the dates and on consulting with a couple of people I came to the conclusion that doing this in Javascript would not be the best solution so I added the following after the query in my function.


<cfset tempArr = arrayNew(1) />
<cfloop query="qry_ContactsList">
<cfset arrayAppend(tempArr, "#DateFormat(qry_ContactsList.visitdate,'dd-mm-yyyy')#")/>
</cfloop>
<cfset qry_ContactsList.addColumn("PRETTYDATE", tempArr) />


This created an additional column in the JSON that was returned, and I could now display the date as I wanted to.

Tuesday, April 15, 2008

Change the Date and Timezone in Centos

Log into your server then retrieve the current date and timezone by typing in

date


all timezone information is stored at /usr/share/zoneinfo you can browse to this by typing

cd /usr/share/zoneinfo


you should see a list of all the available timezones including folders for countries which have multiple time zones eg. America

so to change the time zone just enter the following

ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime


If you then want to manually set the time to 30/03/2008 09:57, the format to enter the date is 'mmddhhmmyyyy'
033009572008


The following command will update your hardware clock
hwclock --systohc


And now when you type in 'date' you should see an up to date clock