PHP Get difference between 2 dates

This code gets the date difference manually, specifying a date value.

$digest_date = "2009-12-25";
$date_diff = abs(strtotime(date('y-m-d'))-strtotime($digest_date)) / 86400;

and another version in a method if you want to keep on reusing this code.

function dateDiff($dformat, $endDate, $beginDate) {
  $date_parts1=explode($dformat, $beginDate);
  $date_parts2=explode($dformat, $endDate);
  $start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
  $end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
  return $end_date - $start_date;

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *