53

2
Q:

## Month since a special date (in decimal)

I would like to have a function that could display how many months it's been since a special date – with decimals if possible.
Anyone have an idea on how to make it? (In PHP)

I ended up doing the following:
`\$var = ((mktime(0,0,0,8,3,2009) - mktime(0,0,0,9,3,2009))/86400/30.4368499);`
Your answers were helpful. James Goodwins was the one leading me to this so he get the "answer solved" mark.

+1  A:
``````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;
}
``````
Thanks. Your answer were the one leading me to the solution.
+1  A:

Try this:

``````echo NumberOfMonths(strtotime('2009-10-02'),strtotime('2008-12-02'));

function NumberOfMonths(\$date1, \$date2) {
\$dates = array(explode(' ',date('Y n',\$date1)),explode(' ',date('Y n',\$date2)));
return (\$dates[0][0]-\$dates[1][0])*12+(\$dates[0][1]-\$dates[1][1]);
}
``````

Although there's no validation on it of course.