using php to find the rounded down number of months between two dates

I want to find the number of days between two dates, then find the fractional number of months between the two dates, then rounddown the number of frational months to a whole number. I know there are a number of ways to do this and was hoping you could give me some tips on the best way. I have reviewed some of the examples on and there are many ways that this can be done.
here is a brief e.g.
$start_date = 11/1/07
$final_date = 11/17/08
$final_date - $start_date = $number of days
$months = $number_of_days/365.25 *12
$months_rounded_down = rounddown($months)

function round_down($num, $d = 0)
    return sgn($num)*p_floor(abs($num), $d);

thanks for the help
Who is Participating?
Ray PaseurConnect With a Mentor Commented:
You should probably carry your dates in ISO8601 format like YYYY-MM-DD.  This is the MySQL DATE format, and is created in PHP with date('Y-m-d').  This format has the advantages of being sortable and unambiguous.  You can make dates pretty for human-readable display, but internally you are better off using the ISO standard.

Days between 2 dates:

Tell us a little bit more about what you want to do with months.  For example, do you want to count the calendar months, not considering the differences in the number of days?  If so, you might use year difference * 12 + (old_month - new_month - 1).  If you want to count 30-day periods, you need a little more math.
sistemuConnect With a Mentor Commented:

The number of days between two dates was already solved in this question:

I am not aware of other, simpler methods, to calculate the number of months.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.