You have a date and time in Epoch seconds that you would like to convert to a date/time object.

Use DateAdd() to add the Epoch seconds to the Epoch date.

ColdFusion does not natively deal with dates based on the Epoch. However, as a developer, you may be faced with situations where you are provided with a date/time value stored in Epoch seconds. If this is the case, you can easily convert the value to a ColdFusion date/time object using the DateAdd() function.

<cfset e=1041397199>
#DateAdd("s",e,DateConvert("utc2Local", "January 1 1970 00:00"))#

In this example, the Epoch is first converted to local time using the DateConvert() function. Next, the number of Epoch seconds we have are added to the converted Epoch time using DateAdd(). The output looks like this:

{ts '2002-12-31 23:59:59'}

Using the DateConvert() function is only necessary if you want to convert Epoch seconds to local time. You can leave it out if you simply want Epoch seconds converted to a date/time object in UTC.

This question was written by Rob Brooks-Bilson
It was last updated on January 6, 2006.




comments powered by Disqus