Convert for example. 2012-05-25 - seconds since January 1, 1970

I have a database where I save time as time() from php, which is seconds since 1 jan 1970 .

Is there a way to convert e.g. 2012-12-12 in seconds since 1 jan 1970 ?

I want to do as:

 SELECT * FROM Table WHERE date > '2012-11-30' AND date < '2012-12-30' 

Is it possible?

(I would like to do this without any php date ())

+7
source share
1 answer

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 .

+15
source

All Articles