Jump to content

Recommended Posts

Hi all, I have been messing up with timezone lately. I solved most of the problems in PHP side, but I have a small issue with mySQL.

 

I store created date in timestamp format using this php function:

 

$date = explode('-', '11-01-2010');
$start_date = gmmktime(0, 0, 0, $date[1], $date[0], $date[2]);

//then i store it into a column called start_time, varchar 255

 

and then, I retrieve it using this mySQL command:

 

select * from event where active=1 and date_format(from_unixtime(start_time), "%d-%m-%Y")='11-01-2010';

 

but apparently, mySQL convert the date to 12-01-2010, not 11-01-2010.. it's the timezone problem. Normally, I would use for-loop, loop through the array and convert the timestamp stored in database using gmdate() function with php. But in this case, I have to do it with mySQL command. Does mySQL have gmdate() equivalent function?

 

Many Thanks!

Link to comment
https://forums.phpfreaks.com/topic/187340-php-gmdate-equivalent-function-in-mysql/
Share on other sites

Use this - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_convert-tz between the from_unixtime() and the date_format() functions.

 

You could also set the mysql timezone to GMT using a query at that start of your code -

SET time_zone = timezone;

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.