Suppose someone from my database was born at -73440000 unix time. This means that he was born on 04- Sep-1967 UTC, but 03 -Sep-1967 EDT. How to count the number of people born on every day of the year in EDT ?
From the very beginning you will find that
SELECT FROM_UNIXTIME(-73440000)
Returns NULL . MySQL cannot handle negative unix timestamps.
Ok, we can get around this:
select date_add('1970-01-01', interval -73440000 second)
Yield 1967-09-04 00:00:00 , which is his date of birth in UTC.
We can try to convert this to EDT (Toronto time):
select convert_tz('1967-09-04 00:00:00','UTC','America/Toronto')
But, as it turned out, CONVERT_TZ does not work in dates until 1970.
( already set time zones and it works with dates between 1970 and 2038 )
So now I'm stuck. I need to convert the unix timestamp to MySQL DATE so that I can have it GROUP BY and then COUNT. The only other option I can think of is to return each record to the database as unix timestamps and use a different language to convert and count them, but this can be a little ridiculous if there are millions of records.
NB You cannot calculate the clock offset between EDT and UTC either because it can change during the year (summer time).
source share