Thursday, December 4, 2008

SQL DateTime > Unix Timestamp

I was blissfully ignorant of UNIX timestamps until a colleague needed to fetch datetime data from one of my servers.

Basically, its just the offset since a given epoch (1st Jan 1970) in seconds.

Returning a Unix timestamp from a SQL Date >
SELECT DATEDIFF(s, '19700101', GETDATE()) 


Returning a SQL Date from a Unix timestamp >
SELECT DATEADD(s,1228348800, '19700101') 


Unix timestamp

No comments: