Hi all,
There are a number of threads relating to the use of mktime and daylight savings but all solutions to my problem have failed.
I am trying to work out all dates between a given start date and end date. Therefore if given 01/01/2004 and 31/12/2004 return all days within these dates in the same format i.e. DD/MM/YYYY.
While my code below works 9 times out of 10. It fails when it gets to say 27/03 and 20/10 which is when daylight saving comes in and out of effect and the PHP script enters an endless loop.
I was led to believe that PHP/Timestamps automatically account for DST as it does for Leap Years. It worked out the 29th of Feb 2004 without any problems.
My code :-
$start_period_date = "01/01/2004";
$end_period_date = "31/12/2004";
$temp_date = $start_period_date;
$temp_day = date("d", $temp_date);
$temp_month = date("m", $temp_date);
$temp_year = date("Y", $temp_date);
while ($temp_date <= $end_period_date && $temp_date != $end_period_date) {
$daily_date = mktime(0, 0, 0, $temp_month, $temp_day + 1, $temp_year);
$temp_date = $daily_date;
$temp_day = date("d", $temp_date);
$temp_month = date("m", $temp_date);
$temp_year = date("Y", $temp_date);
echo "Time Stamp (Seconds): " . $daily_date . " - " . $temp_day . "/" . $temp_month . "/" . $temp_year . " - " . $i . "<br>";
$day_count++;
}
Any help with this would be gratefully received.
Phil.