Click here to get back home

Convert stored mysql DateTime of UTC datetime stamp into another time zone

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Convert stored mysql DateTime of UTC datetime stamp into another time zone Justin Voelker 12-02-2008
Get Chitika Premium
Posted by Justin Voelker on December 2, 2008, 2:48 pm
Please log in for more thread options
Hello everyone:
I have seen posts like this one a couple times looking through this
group but I have yet to find a simple, elegant answer and I know there
must be one. I have a mysql database that has a datetime field in the
format Y-m-d H:i:s for the UTC time of a given post. If I am in the
eastern timezone I am currently at -5 hours from UTC so when I make my
post at 1:00pm eastern time, the time I see dispalyed on the page is
6:00pm because it is 6:00pm UTC. How can I take that UTC datetime
stamp and convert it to the correct datetime given a specific php
timezone such as America/New_York? I know there must be a simple way
to do this I just haven't been searching the right words or
something. Please help! Thank you!!!

Posted by Jerry Stuckle on December 2, 2008, 3:54 pm
Please log in for more thread options
Justin Voelker wrote:
> Hello everyone:
> I have seen posts like this one a couple times looking through this
> group but I have yet to find a simple, elegant answer and I know there
> must be one. I have a mysql database that has a datetime field in the
> format Y-m-d H:i:s for the UTC time of a given post. If I am in the
> eastern timezone I am currently at -5 hours from UTC so when I make my
> post at 1:00pm eastern time, the time I see dispalyed on the page is
> 6:00pm because it is 6:00pm UTC. How can I take that UTC datetime
> stamp and convert it to the correct datetime given a specific php
> timezone such as America/New_York? I know there must be a simple way
> to do this I just haven't been searching the right words or
> something. Please help! Thank you!!!

Among other ways:

echo strftime('%Y-%m-%d %H:%M:%S', strtotime('2008-12-02 20:50:00Z'));

or

echo date('Y-m-d H:i:s', strtotime('2008-12-02 20:50:00Z'));

prints:

2008-12-02 15:50:00

(U.S. Eastern Standard Time)

(Note: the 'Z' at the end of the string is important - it means the
input is in Zulu (UTC) time).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Posted by Justin Voelker on December 4, 2008, 3:19 pm
Please log in for more thread options
> Justin Voelker wrote:
> > Hello everyone:
> > I have seen posts like this one a couple times looking through this
> > group but I have yet to find a simple, elegant answer and I know there
> > must be one. =A0I have a mysql database that has a datetime field in th=
e
> > format Y-m-d H:i:s for the UTC time of a given post. =A0If I am in the
> > eastern timezone I am currently at -5 hours from UTC so when I make my
> > post at 1:00pm eastern time, the time I see dispalyed on the page is
> > 6:00pm because it is 6:00pm UTC. =A0How can I take that UTC datetime
> > stamp and convert it to the correct datetime given a specific php
> > timezone such as America/New_York? =A0I know there must be a simple way
> > to do this I just haven't been searching the right words or
> > something. =A0Please help! =A0Thank you!!!
>
> Among other ways:
>
> echo strftime('%Y-%m-%d %H:%M:%S', strtotime('2008-12-02 20:50:00Z'));
>
> or
>
> echo date('Y-m-d H:i:s', strtotime('2008-12-02 20:50:00Z'));
>
> prints:
>
> 2008-12-02 15:50:00
>
> (U.S. Eastern Standard Time)
>
> (Note: the 'Z' at the end of the string is important - it means the
> input is in Zulu (UTC) time).
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Thank you Jerry:
I think that would work if the user selects a timezone and I set that
timezone on the website using date_default_timezone_set(). The
problem is, when I need to write a date/time back to the database, I
need to set the timezone back to UTC. Is there anything I can do to
convert on the fly rather than constantly switching back and forth
with the date_default_timezone_set() function?

Posted by Jerry Stuckle on December 4, 2008, 4:22 pm
Please log in for more thread options
Justin Voelker wrote:
>> Justin Voelker wrote:
>>> Hello everyone:
>>> I have seen posts like this one a couple times looking through this
>>> group but I have yet to find a simple, elegant answer and I know there
>>> must be one. I have a mysql database that has a datetime field in the
>>> format Y-m-d H:i:s for the UTC time of a given post. If I am in the
>>> eastern timezone I am currently at -5 hours from UTC so when I make my
>>> post at 1:00pm eastern time, the time I see dispalyed on the page is
>>> 6:00pm because it is 6:00pm UTC. How can I take that UTC datetime
>>> stamp and convert it to the correct datetime given a specific php
>>> timezone such as America/New_York? I know there must be a simple way
>>> to do this I just haven't been searching the right words or
>>> something. Please help! Thank you!!!
>> Among other ways:
>>
>> echo strftime('%Y-%m-%d %H:%M:%S', strtotime('2008-12-02 20:50:00Z'));
>>
>> or
>>
>> echo date('Y-m-d H:i:s', strtotime('2008-12-02 20:50:00Z'));
>>
>> prints:
>>
>> 2008-12-02 15:50:00
>>
>> (U.S. Eastern Standard Time)
>>
>> (Note: the 'Z' at the end of the string is important - it means the
>> input is in Zulu (UTC) time).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Thank you Jerry:
> I think that would work if the user selects a timezone and I set that
> timezone on the website using date_default_timezone_set(). The
> problem is, when I need to write a date/time back to the database, I
> need to set the timezone back to UTC. Is there anything I can do to
> convert on the fly rather than constantly switching back and forth
> with the date_default_timezone_set() function?

php.net is your friend.

http://www.php.net/manual/en/function.gmstrftime.php

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Similar ThreadsPosted
Convert datetime to unix timestamp October 23, 2006, 12:49 pm
Using PHP with MySQL Datetime January 16, 2007, 12:02 am
MySQL DATETIME and PHP Dates April 7, 2005, 12:37 am
question about datetime column in mysql October 28, 2006, 11:26 pm
Comparing indexed MySQL datetime columns March 8, 2006, 12:26 pm
Help with comparing date stamp in PHP to date AND time stamp coming from MYSQL db!!!!!! May 8, 2008, 1:21 am
New To php ... Need Help with DateTime October 3, 2005, 10:05 pm
DATETIME field June 27, 2006, 10:15 am
datetime problem October 25, 2006, 2:42 am
datetime manipulation March 3, 2008, 4:23 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap