This is explained in manual :
<?php
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);
echo $interval->format('%a total days')."\n";
echo $interval->format('%m month, %d days');
?>
Do you want to:
function check($dt) {
$date = date("Y-m-d");
$start = new DateTime($date);
$end = new DateTime($dt);
$diff = $start->diff( $end );
return $diff->format( '%a days' );
}
print check('2009-12-14');
gives 180 days.
source
share