Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in T-SQL

🎈 🎈 🎈
+1

    SELECT DATEADD(SECOND, [UnixTimestamp], '1970-01-01 00:00:00') AS Date
    FROM YourTable;        
        

Output:
--------------------------- | Date | --------------------------- | 2020-05-18 20:27:01 |
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this query, 'UnixTimestamp' is the column that contains the Unix timestamp value (eg 1589833621) and '1970-01-01 00:00:00' is the Unix epoch start date.
The DATEADD function adds the number of seconds specified in the 'UnixTimestamp' to the epoch date, resulting in a Date column that displays the corresponding date and time for each Unix timestamp.
In this example the Date column would contain the date 2020-05-18 20:27:01.


Other useful T-SQL date functions

Function Description Example
GETDATE() Returns the current date and time of the system in the format 'YYYY-MM-DD HH:MM:SS.mmm'. GETDATE() returns 2024-08-28 12:34:56.789
GETUTCDATE() Returns the current UTC date and time in the format 'YYYY-MM-DD HH:MM:SS.mmm'. GETUTCDATE() returns 2024-08-28 16:34:56.789
DATEADD() Adds a specified number of time units (e.g., days, months, years) to a date. DATEADD(DAY, 5, '2024-08-28') returns 2024-09-02
DATEDIFF() Returns the difference between two dates as an integer in specified time units (e.g., days, months, years). DATEDIFF(DAY, '2024-08-28', '2024-09-02') returns 5
FORMAT() Formats a date/time value according to the specified format string. FORMAT(GETDATE(), 'dd/MM/yyyy') returns 28/08/2024
EOMONTH() Returns the last day of the month that contains the specified date, with an optional offset. EOMONTH('2024-08-28') returns 2024-08-31
YEAR() Returns the year part of a date. YEAR('2024-08-28') returns 2024
MONTH() Returns the month part of a date. MONTH('2024-08-28') returns 8
DAY() Returns the day part of a date. DAY('2024-08-28') returns 28
SWITCHOFFSET() Adjusts a datetimeoffset value by a specified time zone offset. SWITCHOFFSET('2024-08-28 12:34:56.789 +00:00', '-08:00') returns 2024-08-28 04:34:56.789 -08:00
SYSDATETIME() Returns the current date and time as a datetime2 value, with higher precision than GETDATE(). SYSDATETIME() returns 2024-08-28 12:34:56.7891234
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