[Resolved] Formatting MySQL's DATETIME plus or minus a COOKIE value
Hello all.
I have a DATETIME field in a MySQL database, called date_entered, into which I am inserting Greenwich Mean times via PHP like so:
The dates in the database look something like this:
Code:
2005-08-02 00:01:01
When I retrieve the database column, the PHP code looks like this:
Code:
echo $row->date_entered;
I also have a COOKIE called $_COOKIE['time_zone'] which stores values such as: -5 (for Eastern Standard Time), +1 (for Madrid), +2 (for Athens), etc. (I set Greenwich to 0, btw.)
Now, how would I add the value of $_COOKIE['time_zone'] to the result of the database column, then format it into, say:
Aug 02, 2005
Many thanks to anyone who can help me with this.
Re: Formatting MySQL's DATETIME plus or minus a COOKIE value
I think the best way to do this would be to find the servers time, then calculate the difference in hours between local time and the time of the server.
e.g. Server time is- 16:00, the time in Belgium is 20:00, so the difference is 4 hours.
So to get the local time (time in Belgium) the code would look like this:
PHP Code:
$differencetolocaltime=4;
$new_U=date("U")-$differencetolocaltime*3600;
print date("H:i", $new_U);
Hope this helps.
-chris
Re: Formatting MySQL's DATETIME plus or minus a COOKIE value
Why thank you Chris. I'd call this one resolved. :)