Convert eg. 2012-05-25 to seconds since January 1 1970 Convert eg. 2012-05-25 to seconds since January 1 1970 sql-server sql-server

Convert eg. 2012-05-25 to seconds since January 1 1970


DATEDIFF is going to be your friend here:

select datediff(s, '1970-01-01', '2012-12-12') as SecondsSinceEpoch

Note that because datediff returns an int, the maximum datetime you can compare (using seconds) with Jan 1st, 1970 is 2038-01-19 03:14:07.