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.
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 Unix time for now run this
To get the Unix time for January 1, 2001 run this
- SELECT DATEDIFF(s,'19700101 05:00:00:000','20000101 05:00:00:000')
We need to add 5 hours to 20000101, if you are running this from a GMT-5 timezone (I am based in Princeton, NJ which is 5 hours behind GMT)
See also http://wiki.lessthandot.com/index.php/Converting_Unix_time_to_SQL_Server_datetime it shows you how to go from Unix time to datetime.
Contributed by: --SQLDenis 16:52, 30 May 2008 (GMT)
Part of SQL Server Programming Hacks