cancel
Showing results for 
Search instead for 
Did you mean: 

PHP5 Date() and BST

RobDickson
Grafter
Posts: 633
Thanks: 2
Registered: ‎06-08-2007

PHP5 Date() and BST

I'm trying to figure out whether my PHP code is displaying the correct information. The code is:
Quote
$datetime = mktime(10,0,0,9,1,2007,1);
$date = mktime(0,0,0,9,1,2007,1);
echo date("Y-m-d H:i:s e",$datetime);
echo "<br>";
echo date("Y-m-d",$date);
echo "<br>";
echo date("I",$date);

The output is:
Quote
2007-09-01 09:00:00 UTC
2007-08-31
0

Before the clocks went back, the output would have been:
Quote
2007-09-01 10:00:00 BST
2007-09-01
1

It seems that the date("I",$date) is deciding whether the date is in BST, or not, based on the current date, not the date in the script.
Basically, all the dates and times on my site are now displayed in GMT. This isn't a problem, but during the summer they will be displayed in BST, even those times that are for dates in GMT.
Am I missing something obvious here, or is this how PHP5 should operate?
As far as displaying 31st August, instead of 1st September is concerned, this is explained here:
http://bugs.php.net/bug.php?id=461
2 REPLIES 2
mar7t1n
Grafter
Posts: 93
Thanks: 5
Registered: ‎09-08-2007

Re: PHP5 Date() and BST

Rob, the format of PHP mktime is:
mktime ( hour, minute, second, month, day, year, is_dst )
The purpose of is_dst is to determine if the date is when daylight saving is active. It's probably best to just leave this parameter so that PHP can make it's own mind up.
If I run this code on a local machine using the latest PHP 5.2.4
echo date("Y-m-d H:i:s e T ",$datetime) . "<br>";
I get:
2007-09-01 10:00:00 Europe/London BST - For September
2007-11-01 10:00:00 Europe/London GMT - For November
Which is exactly as I'd expect. But I guess it depends which version of PHP the server is running and whether it knows when the clocks change, and what the OS is.
I had great fun with the clocks changing last year on an online booking system I manage at (www.underthethatch.co.uk). It incorrecty said the booking was for one day less than expected, because I used to increment time by adding 86400.
RobDickson
Grafter
Posts: 633
Thanks: 2
Registered: ‎06-08-2007

Re: PHP5 Date() and BST

My host is running PHP5.2.4 on Apache/Linux, and the server is showing the correct time.
I'm sure the solution is obvious, I just need to find out what it is....