Reputation: 551
I am developing a web application in which remainders will be sent to subscribers at a particular time of the day. Let's say a person John fills a form and asks to send email remainder at 12 pm every day. I have developed a cron job for this purpose but I am having issues related to time. Here is my problem if John is from USA then the email have to be sent according to US time and so on. Now I use MYSQL to store the time zone and Time from each person. But How do I schedule the emails according to specific time zone. My server time is set to UTC. So if a person has time zone of GMT +5 how many hours I have to add in the UTC so that emails should be sent at correct time.
I don't need the code just give me a common formula to calculate the correct time of email.
Thanks a lot,
Ahmar.
Upvotes: 0
Views: 244
Reputation: 1542
Don't calculate it, use the database. Mysql has the best timezone support of any of the mainstream RDBMS. Its even better than Oracle as far as having sensible ways of updating its database from Olson.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz
Should give you a clue.
Upvotes: 1
Reputation: 5701
Take a look at the convert-tz
function.
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
-> '2004-01-01 13:00:00'
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
-> '2004-01-01 22:00:00'
Upvotes: 1