DATEDIFF will be your friend here:
select datediff(s, '1970-01-01', '2012-12-12') as SecondsSinceEpoch
Please note that since dateiff returns int, the maximum datetime that you can compare (using seconds) since January 1, 1970, 2038-01-19 03:14:07 .
Tim lehner
source share