Time / date calculation

Hi,

Why there’s difference between the following ?

<?php
$days = 8;

$strdate = mktime (0,0,0,10,27,2013);
$end_mk = mktime (0,0,0,10, (27 + $days), 2013);

$end_ti = $strdate + ($days * 24 * 60 * 60);

echo "Days to Add: " . $days . "<br />\
";
echo "Start Date via mktime: " . date("d-m-Y", $strdate) . "<br />\
";
echo "End Date via mktime: " . date("d-m-Y", $end_mk) . "<br />\
";
echo "End Date via time: " . date("d-m-Y", $end_ti) . "<br />\
";
?>

Thanks.

DST.

Hi,

You mean to say that mktime calculates correctly and multiplication does’nt ?

Thanks.

Apparently so. If you change your test dates to Sept or Apr or May it all works. Only Oct fails. Doing a search I found that 11/3/13 is the day we change time in US, so that’s it.

Also - if you read the manual for mktime, one of the notes is quite specific about NOT using seconds arithmetic to modify dates. Doesn’t explain why, but apparently you’re not the first to discover this hole.

Hi,

Hmm, i had thought about DST but then someone told me that it only effects just an hour, so I stopped thinking about it. But now I reliazed that mktime is much efficient at all this.

Thanks.

I messed round with this problem a while ago:

The function I wrote worked fine I think. Also what [CENTER]PHP Guru talked about looks good.[/CENTER]