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

1

8

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

Is there any way I can convert, for example 2012-12-12 to seconds since 1 jan 1970?

I want to do like:

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

Is this even possible?

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

Polythene answered 16/10, 2012 at 21:28 Comment(1)
google.com/…Procrustean
T
17

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.

Tabriz answered 16/10, 2012 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.