Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
PHP5 Date() and BST
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- PHP5 Date() and BST
PHP5 Date() and BST
29-10-2007 12:42 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I'm trying to figure out whether my PHP code is displaying the correct information. The code is:
The output is:
Before the clocks went back, the output would have been:
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
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
Message 1 of 3
(1,645 Views)
2 REPLIES 2
Re: PHP5 Date() and BST
30-10-2007 2:17 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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.
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.
Message 2 of 3
(445 Views)
Re: PHP5 Date() and BST
30-10-2007 7:33 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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....
I'm sure the solution is obvious, I just need to find out what it is....
Message 3 of 3
(445 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page