I have a little, but nasty problem:
I have a database with many records, every record has two fields with mysql timestamps, like this:
2012-02-14 11:09:59
and since every row has it’s individual timezone (i saved the timezone as string, such as “Europe/Berlin” and also as offset like +1 in a float field), i have a little problem:
I want to query the db for records that are newer or older than -now-
I could convert the date to GMT and search them with the servers tmz-offset.
Easy, buuuuttt, the trouble is, i want to have the possibility to search for records that happen at a certain local time, like for instance:
I want to search for a thing that happens at 22:00 tomorrow all over the world.
Now if i convert all timestamps to GMT i could not do that, because in the where condition 22:00 is not going to be the local time, but the GMT-time…
Is there any way i could combine the timestamp and the tmz field in one query?
Thanks 1000 in advance!
I think the ideal solution would be either to
Store all times in UTC and do the offset calculations when outputting the date
or have a second, separate column with the UTC date.
However, your original requirement should be possible as well – use
DATE_ADD()to calculate the correct offset: