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.

<?php
$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?

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"));
}
else
{
$nextWeek = date(strtotime("+7 days"));
}

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

Hope this helps.

commented: Very good, solved my problem +1

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.