coldfusionunix-timestampcfml

Convert ColdFusion Date to Unix timestamp


How can I convert a ColdFusion date to Unix Timestamp?

myDate = DateAdd("m", -1, Now());

I would like to convert myDate to unix timestamp using ColdFusion

Thanks


Solution

  • Just create the UNIX origin date, and do a DateDiff from then to now (or whatever your date variable is) in seconds.

    <cfset startDate = createdatetime( '1970','01','01','00','00','00' )>  
    <cfset datetimeNow = dateConvert( "local2Utc", now() )>
    <cfset UnixStamp = datediff( 's', startdate, datetimeNow )>