i've the following code:
$dStart = new DateTime('2013-03-15');
$dEnd = new DateTime('2013-04-01');
$dDiff = $dStart->diff($dEnd);
echo $dDiff->days;
I don't know why i'm getting 6015 as result.
$date1 = "2007-03-24"; $date2 = "2009-06-26"; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); printf("%d years, %d months, %d ...
Use the DATEDIF function when you want to calculate the difference between two dates. First put a start date in a cell, and an end date in another. Then type a formula like one of the following. Warning: If the Start_date is greater than the End_date, the result will be #NUM!.
To calculate the difference between two dates in PHP, call date_diff() date/time function, and pass the two dates as argument to it. date_diff() function returns a DateInterval object, or FALSE if calculating the difference is not successful.
In order to compare those two dates we use the method diff() of the first DateTime object with the second DateTime object as argument. The diff() method will return a new object of type DateInterval .
Try like
$dStart = strtotime('2013-03-15');
$dEnd = strtotime('2013-04-01');
$dDiff = $dEnd - $dStart;
echo date('H:i:s',$dDiff);
or as per your code try with
$dDiff = $dStart->diff($dEnd);
$date->format('d',$dDiff);
echo $dDiff->days;
if you want diff in days try with this also
echo floor($dDiff/(60*60*24));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With