Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Epoch Date

From Wiki

Jump to: navigation, search

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

  1. SELECT DATEDIFF(s,'19700101 05:00:00:000',GETUTCDATE())


To get the Unix time for January 1, 2001 run this

  1. 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

Section Dates

121 Rating: 3.0/5 (32 votes cast)