For example, on March 13, we know the start and end of the day. How to calculate the intermediate date. For example, on March 13, we know the start and end of the day. How to calculate the intermediate date.
Reply content:
For example, on March 13, we know the start and end of the day. How to calculate the intermediate date.
Since the start and end time are known, the end time stamp minus the start time stamp difference divided by 86400 is the number of days
If it is to get the intermediate date, I think the upstairsSouth Bird
The code is not concise, as shown below:
$start = new DateTime('2016-09-15');$end = new DateTime('2016-09-17');for ($start;$start<=$end;$start->modify('+1 day')) { echo $start->format('Y-m-d')."
";}
We recommend the best PHP time processing extension I have used: Carbon. basically, all the time-related calculations can be done.
Carbon is more convenient
However, PHP has this function by default.
$start = new DateTime('2016-09-15');$end = new DateTime('2016-09-17');$inteval = new DateInteval('P1D');$period = new DatePeriod($start, $end, $inteval);foreach ($period as $date) {}
$start = '2016-09-15';$end = '2016-09-17';$start = strtotime($start);$end = strtotime($end);$days = ($end - $start) / 3600 / 24;for ($i = 0; $i <= $days; $i++) { echo date('Y-m-d', $start + 3600 * 24 * $i) . "
";}2016-09-152016-09-162016-09-17