Hello, I am having this wierd issue, probably have to due with time zones... Anyway when I do SELECT NOW(); Code (markup): query in Mysql it returns "2011-08-30 22:46:28" but when I do echo date("Y-m-d h:m:s",time()); Code (markup): In PHP it returns "2011-08-30 07:08:09" Any Idea how to make them return the same results or better ways to store time ETC.... ? Thanks in advance, Kind Regards. Issa Shamoun.
under <?php place date_default_timezone_set('UTC'); // UTC, GMT or whatever zone your looking to set PHP:
Did you run these at the same time? You shouldn't have servers 30 minutes apart no matter what method you are using to standardize the times.
I will check this one out and see for my self but is there anyway to change mysql time zone instead of php ?
MySQL returns your server's current time no matter what timezone your in, while PHP returns UTC time (GMT)
MySql stores values from your input, ie: your php INSERT, so you should perhaps alter your INSERT code to reflect the time of input from your time zone.... date_default_timezone_set('UTC'); // UTC, GMT or whatever zone your looking to set Code (markup): ...rather then letting the mysql server determine it.
If this is on your own computer, you have a major problem (the 30 minute difference). If this is on a site you buy hosting for, call tech support at your host and ask them to time-synchronize their servers. They have MySQL running on a different computer than the site is running on (which is common) and the two computers have different times.
Oops. Try echo date("Y-m-d h:i:s",time()); ("m" is the month, not the minute. See http://php.net/manual/en/function.date.php)
*I* didn't figure it out, the PHP interpreter did. I stuck the code into my test file and noticed that the "minute" was the month, even as the time advanced. The date() function wants the format in "date" in the chm file, not the one in "date formats". You also need date_default_timezone_set() set to the timezone (UTC or your own) to get the correct hour. There's a list of the valid ones in the manual (online or the enhanced chm file - the one with the comments).