Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Converting Unix time to SQL Server datetime
Unix time, or POSIX time, is a system for describing points in time: it is the number of seconds elapsed since midnight UTC of January 1, 1970, not counting leap seconds
Here is how you do it in SQL Server. To get the datetime value for a value stored in Unix time you need to add the seconds to the base Unit time which is '19700101 05:00:00:000'
The following code will give you an output of '2010-05-25 07:56:23.000'
To get the datetime for Unix time for January 1, 2001 run this
See also http://wiki.lessthandot.com/index.php/Epoch_Date for the reverse, converting from datetime to Unix time
Contributed by: --SQLDenis 17:32, 25 May 2010 (GMT)
Part of SQL Server Programming Hacks