Jump to content

subtract dates returning 0


dolcezza

Recommended Posts

This is returning 0 with the dates 2010-05-05 ($info['date'])and 2010-05-07($info['enddate']). What am I doing wrong?

Thanks in advance

 

$date_diff = subtract_dates($info['date'] , $info['enddate']);
//function to find difference between two dates
function subtract_dates($begin_date, $end_date)
{
return round(((strtotime($end_date) - strtotime($begin_date)) / 86400));
}
echo $date_diff;

Link to comment
https://forums.phpfreaks.com/topic/92198-subtract-dates-returning-0/
Share on other sites

I'd check your inputs. When I run this I get 2, as expected

<?php
function subtract_dates($begin_date, $end_date)
{
    //function to find difference between two dates  
    
    return round(((strtotime($end_date) - strtotime($begin_date)) / 86400));
}

$info = array (
        'date' => '2010-05-05', 
        'enddate' => '2010-05-07'
        );

$date_diff = subtract_dates($info['date'] , $info['enddate']);

echo $date_diff;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.