Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in ColdFusion

How to convert Unix timestamp to Datetime in ColdFusion

🎈 🎈 🎈
+1

    <cfset unixTimestamp = 1192770288>

    <!-- Convert Unix timestamp to date -->
    <cfset dateTime = DateAdd("s", unixTimestamp, CreateDateTime(1970, 1, 1, 0, 0, 0))>
    
    <cfoutput>
        Converted Date: #dateTime#
    </cfoutput>
        

Output:
Converted Date: 2007-10-19 05:04:48
Example only. There may be multiple ways to perform this operation.

Code Explanation

In ColdFusion, converting a Unix timestamp to a human-readable date is done using the DateAdd() function. A Unix timestamp represents the number of seconds that have passed since January 1, 1970 (the Unix epoch). The DateAdd() function adds this number of seconds to the Unix epoch to calculate the corresponding date and time.
In the example, the Unix timestamp '1192770288' is added to '1970-01-01 00:00:00' using DateAdd("s", unixTimestamp, CreateDateTime(1970, 1, 1, 0, 0, 0)). The result is a dateTime object representing the date '2007-10-19 05:04:48', which is then displayed using the cfoutput tag.



Other useful ColdFusion date functions

Function Description Example
CreateDateTime() Creates a datetime object from the specified year, month, day, hour, minute, and second. CreateDateTime(2022, 5, 15, 8, 30, 45) returns May 15, 2022 08:10:45
DateAdd() Adds a specified time interval (e.g., days, hours, seconds) to a date or datetime object. DateAdd("d", 5, now()) adds 5 days to the current date.
DateDiff() Returns the difference between two dates in the specified interval (e.g., days, hours, seconds). DateDiff("s", CreateDateTime(1970, 1, 1, 0, 0, 0), now()) returns the difference in seconds since the Unix epoch.
Now() Returns the current date and time. Now() returns 2024-08-28 12:34:56
Day() Returns the day of the month from a specified date. Day(Now()) returns 28 if the current day is the 28th.
Month() Returns the month from a specified date. Month(Now()) returns 8 for August.
Year() Returns the year from a specified date. Year(Now()) returns 2024.
TimeFormat() Formats a time as a string according to the given mask. TimeFormat(Now(), "HH:mm:ss") returns 12:34:56.
DateFormat() Formats a date as a string according to the given mask. DateFormat(Now(), "yyyy-mm-dd") returns 2024-08-28.
GetDayOfWeek() Returns the day of the week as a number (1=Sunday, 7=Saturday). GetDayOfWeek(Now()) returns 4 for Wednesday.
GetTimeZoneInfo() Returns information about the current time zone, including the name and offset from UTC. GetTimeZoneInfo() returns {isDST=true, rawOffset=-300, timezone='America/New_York'}.
ParseDateTime() Converts a string to a datetime object based on the date and time format. ParseDateTime("2022-05-15 08:10:45") returns May 15, 2022 08:10:45.
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder