I had the need to convert a ColdFusion date/time stamp to a JS Date Object. I thought serializeJSON() function would handle this, but it turns out it treats CF date/time variables as strings. The toScript() function will convert CF variables to JS Date Objects—provided that the date/time variable is in ODBC format (i.e. {ts '2008-05-02 13:32:16'}.)
However, I wanted something that would work for anything that ColdFusion saw as a Date object, so I just whipped out this little 4 line helper function:
If ColdFusion doesn't see the date as a date object, then it'll set the date/time to "null". To use this function you just do:
This would then generate the following:
Obviously this is pretty straightforward, but it's saved me a lot of repetitive typing today and simplified the readability of my code.
10 Comments
Comments for this entry have been disabled.