Timezone offsets (and st/dst changes) in MySQL / PHP

zwartschaap

New Member
Basically I have a site that allows stores to store their open/close times.Now, I'm trying to add the feature of giving their visitors the ability to see if the store is closed.I understand I can run a query like:\[code\]SELECT * FROM `store_hours` WHERE TIME(NOW()) BETWEEN `opens` AND `closes`\[/code\]... and the query works and retrieves the stores that are currently open. However, at first this query didn't put into consideration the store's timezone.SO.. I decided to store the store's open/close times with the conversion to UTC attached:id | store_id | opens | closes | utc_opens | utc_closesNow I can query like so:\[code\]SELECT * FROM `store_hours` WHERE TIME(NOW()) BETWEEN `utc_opens` AND `utc_closes`\[/code\]So now I can easily get a global list of how many stores are open and it doesn't even matter where they are.Now I came to this problem. Through PHP, all I did was add the offset to the timestamp:\[code\]date('H:i', strtotime($values['closes']) + $offset)\[/code\]Then I started thinking about Pacific Standard Time and then Daylight Savings Time.I want to add this open/close feature and it will become a huge part of the system. It's just that I will lose out on a lot of income if I'm off by an hour.What's the best way to achieve what I'm trying to accomplish?
 
Back
Top