UNIX booking date stored returns wrong time during BST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
midcalf
Forum Newbie
Posts: 1
Joined: Wed Jun 25, 2008 1:33 am

UNIX booking date stored returns wrong time during BST

Post by midcalf »

Hi there,

A problem with my php code has developed during the switch to British Summer Time. In essence, my small business sells experience vouchers for studio recording days (http://www.giftdaze.co.uk). So for example, uncle jim buys little nephew sammy a 1 hour singing experience. Little sammy then receives his gift and calls us to book a date in the diary. My online diary stores this date as a ten digit INT (unix format created from mktime(bla bla bla)) in my MYSQL database. After the switch to BST, the dates returned are an hour ahead of what they should be, and I'm guessing they'll be right again when standard GMT switches back in again.
How could it be that you store a date as a unix time stamp, then when you recall it and use something like ECHO DATE("g.ia",$STOREDUNIX); it returns the time + 1 hour for BST - this is not good for someone who has an hour booking in the studio! They turn up as there session finishes!

perhaps I can switch off BST on the server thus keeping all the dates in one time frame?

I've obviously understood the date function wrong, and should probably store the date some other fashion I guess. I've mucked about with GMDATE a little thinking this may help the situation but it did'nt.

Any suggestions on how I should refashion my code to give me a simple, correct date, that I can still index and search through MYSQL. I'll take another look at the MYSQL to see if I'm using the wrong function or maybe find a better way to store my dates.

Regards,
Paul MIDCALF
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: UNIX booking date stored returns wrong time during BST

Post by jayshields »

I don't understand. So someone books in for 2009-05-15 14:00:00 and put that into your MySQL DATETIME field. When you come to fetch that out, you get 2009-05-15 15:00:00? I don't believe that!
Post some example code please.

Oh. I think you're storing your date/time as a unix timestamp in your database. Don't bother, just store it in the format shown above, in a DATETIME field. If you want to fetch it back out as a unix timestamp you can use the MySQL function UNIXTIMESTAMP().
Post Reply