I have come up with a day comparison script and it worked fine until daylight saving kicked in. Now all the dates i insert into my database are 1 hour faster. So current date plus 7 days = 7 days + 1 hour. How do i solve this? The code below shows what i am trying to do.

$when = time (void);
echo $when;

$nextWeek = date(strtotime("+7 days"));
echo "<br />";
echo $nextWeek;
echo "<br />";

$date = $when;
$date2 = $nextWeek;

    $newdate = strftime($date2 - $date);
	echo date('d',($newdate))."Days";
	echo date('H',($newdate))."Hours";
	echo date('i',($newdate))."Minutes";

Now i cant get rid of that one hour that has just appeared.
Can anyone advise me on how to fix this please?

8 Years
Discussion Span
Last Post by ripper1510

There's a PHP date variable which determines whether daylight saving is currently in place.

date("I") returns 1 if daylight saving time, else it returns 0.

In place of your $nextWeek try using:

if (date("I") == 1)
$nextWeek = date(strtotime("+6 days -1 hour"));
$nextWeek = date(strtotime("+7 days"));

I've used +6 days - 1 hour because for some reason it adds 8 days otherwise.

Hope this helps.

Votes + Comments
Very good, solved my problem

That works perfectly thank you very much. I just need to play around with it some more. The scenario that it is running in is very complex so i just need to test it fully.
But thank you very very much for solving my problem

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.