I want to increment Timestamp to generate dates (timestamps being assumed with time=0 hour, 0 minute, 0 second). All worked fine along my loop unless the day of 2016-10-30: Example follows:
$date1=new DateTime;
$date1->setDate(2016,10,30);
$date1->setTime(0,0,0);
$date1_str=$date1->format('Y-m-d H:i:s');
$timestamp1=$date1->getTimestamp();
$timestamp2=$timestamp1+(60*60*24);// create the next day...
$date2=new DateTime;
$date2->setTimestamp($timestamp2);
$date2_str=$date2->format('Y-m-d H:i:s');
echo "date1_str=$date1_str; date2_str=$date2_str<br>";
The result I get is the following:
date1_str=2016-10-30 00:00:00; date2_str=2016-10-30 23:00:00
The 24 hours increment of timestamp is seen as a 23 hours increment!! The remaing of the loop keep locked to time 23:00:00 instead of 00:00:00
$timestamp2=$timestamp1+(60*60*24);suggests that you're assuming that every day of the year has 24 hours$date = new DateTime('2016-10-30'); $date->modify('+1 days');does the same as your code. Not saying shorter is always better, but in this case I think it is