Home > Date Time, PHP > Months Difference Between Dates

Months Difference Between Dates

$date1 = “2011-03-26”;
$date2 = “2011-04-25”;
$yMdDiffArray = noOfDaysDifference ($date1,$date2);

function noOfDaysDifference($fromDate,$todate)
{

$dateArray = explode(‘-‘,$todate);
$plusOne = 1;
$to_date = Date(‘Y-m-d’,mktime(0,0,0,$dateArray[1],$dateArray[2]+$plusOne,$dateArray[0]));

$noOfdays =(strtotime($to_date) – strtotime($fromDate)) / (60 * 60 * 24);
Return $noOfdays;
}

Advertisements
Categories: Date Time, PHP Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: