Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,005
0
London , UK
Hi all,

Im manipulating dates in PHP and then saving them for latter use in the GMT format.

(I will be using it in RSS in the format Wed, 13 Feb 2008 17:22:00 GMT).

The problem is when you store a date you do not get the exact time in the summer as it is 1hour ahead so you have to put for example:

Sun, 1 Jun 2008 14:00:00 GMT -0100

Is there anyway of finding out using php whether daylight saving is in effect on the given date so the appropriate adjustment can be made ?
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
You can check if daylight savings is in effect. http://us3.php.net/gmdate Do a search for daylight on this page and you'll find an example. Essentially date("I"); will return 1 is daylight savings is current, 0 otherwise.
 

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,005
0
London , UK
Thanks for that but I have a problem it always returns 0

First is of each date is done using date()
Seconds using gmdate()


Jun 01 2008 00:00:00 0
Jun 01 2008 07:00:00 0

Jan 01 2008 00:00:00 0
Jan 01 2008 07:00:00 0

Code:
echo date("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
echo "<br/>";
echo gmdate("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
echo "<br/>";
echo "<br/>";

echo date("M d Y H:i:s I ", mktime(0, 0, 0, 1, 1, 2008));
echo "<br/>";
echo gmdate("M d Y H:i:s I", mktime(0, 0, 0, 1, 1, 2008));
echo "<br/>";
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
I ran your PHP and get,

Jun 01 2008 00:00:00 1
Jun 01 2008 04:00:00 0

Jan 01 2008 00:00:00 0
Jan 01 2008 05:00:00 0


So I'm getting thr correct results ... for whatever reason. Maybe it's a server setting then.
 

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,005
0
London , UK
I ran your PHP and get,

Jun 01 2008 00:00:00 1
Jun 01 2008 04:00:00 0

Jan 01 2008 00:00:00 0
Jan 01 2008 05:00:00 0


So I'm getting thr correct results ... for whatever reason. Maybe it's a server setting then.

Thanks I appreciate the help :D

I get my results both on my mac and on my go daddy hosting account, im surprised they both give incorrect values.
 

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,005
0
London , UK

yeah that works:

Code:
<?php
date_default_timezone_set('Europe/London');


echo date("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
echo "<br/>";
echo gmdate("M d Y H:i:s I ", mktime(0, 0, 0, 6, 1, 2008));
echo "<br/>";
echo "<br/>";

echo date("M d Y H:i:s I ", mktime(0, 0, 0, 1, 1, 2008));
echo "<br/>";
echo gmdate("M d Y H:i:s I", mktime(0, 0, 0, 1, 1, 2008));
echo "<br/>";
?>


Produces

Jun 01 2008 00:00:00 1
May 31 2008 23:00:00 0

Jan 01 2008 00:00:00 0
Jan 01 2008 00:00:00 0

Thanks for your help angelwatt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.