I have two dates of the form:
Start Date: 2013-05-19
End Date: 2013-05-21
Now I need to find the difference between these two in the following form:
2013-05-20
2013-05-21
How can I do this in PHP?
I have two dates of the form:
Start Date: 2013-05-19
End Date: 2013-05-21
Now I need to find the difference between these two in the following form:
2013-05-20
2013-05-21
How can I do this in PHP?
this should help converting iso to unix: http://www.laughing-buddha.net/php/dates Most efficient way to convert a ISO Date into Unix timestamp?
you could then subtract one date from the other, divide by 3600 and end up with the difference in days, if i understood the question properly
This
$startDate = strtotime($date1);
$endDate = strtotime($date2);
$dates = array();
for($x = $startDate, $x <= $endDate; $x+=86400){
$dates[] = date("Y-m-d", strtotime($x));
}
should give you what you want.
You can do something like:
$date_difference = strtotime('2013-05-21') - strtotime('2013-05-19');
That'll give you the seconds between the two dates. If you want that in days, just divide by 86400.
You can also use date_diff if using PHP 5.3+.
Use can utilize DatePeriod
class
$begin = new DateTime( '2013-05-19 + 1 day' );
$end = new DateTime( '2013-05-21 + 1 day' );
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Y-m-d") . "<br>";
}
Output:
2013-05-20
2013-05-21