RE: [PHP] correcting a date with a time-zone field
| From: | Ford, Mike [LSS] | Date: | Thu, 10 Apr 2003 16:56:13 +0000 |
| Subject: | RE: [PHP] correcting a date with a time-zone field | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-143361@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: julien Beauviala [mailto:php-l@aaton.com]
> Sent: 10 April 2003 14:45
>
> I have two fields in a MySQL db, one is date-time and
> one is time zone, in th following format:
>
> 2003-04-10 13:08:28
> +0200
>
> Time zones can be anywhere from +1000 to -1000
>
> I need to find a way to add that time zone field to
> the date field to get a proper GMT time :
>
> 2003-04-10 15:08:28
Assuming you have $date_time and $time_zone, try:
gmdate('Y-m-d H:i:s', strtotime("${date_time}${time_zone}"))
(untested, but should work).
>
> The time zone field can contain other stuff, like (PDT)
> but they always start with ([+-])(\d{2})
>
> Once I have that, I'll need to substract 2 hours to get
> the right time relative to our own time zone.
If the server you are running this on is set to the timezone you want, just
do a date() instead of a gmdate(). Otherwise, I suppose you could do
something like:
gmdate('Y-m-d H:i:s', strtotime("${date_time}${time_zone}")-(2*60*60))
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211