php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #22652 Please add functions to convert between timezones
Submitted: 2003-03-11 23:02 UTC Modified: 2005-09-03 13:06 UTC
Votes:5
Avg. Score:4.2 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:2 (50.0%)
From: photon at comcast dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.1 OS: Linux
Private report: No CVE-ID: None
 [2003-03-11 23:02 UTC] photon at comcast dot net
Hi,

PHP seems to have some innate knowledge of time zones, but I find it very lacking for this very simple thing.  Say I have a server in California, but I live in NJ.  An m-time, say, of a file on the server is displayed on my website, but it's in Pacific Time.  I want it in Eastern Time.  

It's not as simple as just adding 3 hours either, as Daylight Savings Time must be taken into effect.  Not just one DST crossover either, as the crossovers will be at different times.

To these ends, I propose three new date functions for PHP: a generalized converttime(int timestamp, string timezone1, string timezone2) which could be used easily to convert a time between two known DAYLIGHT-AWARE time zones, like so:

echo converttime(time(), PT, ET)

It would take the timestamp, see if it was daylight-time in PT, calculate the offset, check same for ET, convert.

Also convertfromlocal which could do this (known ET timestamp, want to convert to local time):

echo convertfromlocal(time(), ET)

and convertolocal (say I knew I had a PT timestamp and I wanted it in ET (with the machine running on PST))

echo converttolocal(time(), PT)

Thank you :)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-14 14:29 UTC] daniel at NO dot brightbyte dot SPAM dot de
The lack of timezone-conversion function is really a major problem. Please supply that functionality, there are plenty of libs out there to build on.

With to regards to what the original author suggested: functions like converttime() are a BAD idead, as they suggest converting the time-stamp -- which is, by definition, always in UTC. Instead, it would be much better to give the date() function an optional third parameter: the time zone. This would be consistent with the way this is handeled in other languages, like Perl. For a start, it would even be sufficient to only allow simple offsets of the form +0500 there -- but it would indeed be extremely helpful to allow DST-Aware zones (like Olson-DB zones).

I currently have this problem with a server in germany, that needs to display Vancouver time. As i don't want to do all the DST-conversion by hand, i'm stuck with using an external tool (written in perl) to convert from a unix-timestamp to a Vancouver date. This works well, but it's extremely slow. Also, it requires installation of a bunch of Perl-Modules on the server....

Oh, yea: this feature is still lacking under 4.3.4, and i see no mention in the documentation of supplying something like that in PHP 5... please, do!

thanks.
 [2004-06-14 14:34 UTC] derick@php.net
This is in the works for PHP 5.1, please be patient for a while.
 [2005-09-03 13:06 UTC] derick@php.net
This kind of functionality will be avaiable in PHP 5.1.1 and PHP 6.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 14:01:33 2025 UTC