# *SOLVED* Months between

## Recommended Posts

What's the easiest way to work out the number of months between two dates?

I've been looking at the date() and time() functions and can probably figure out a way to work it but wondered if their was a function already?

Regards
Rich
##### Share on other sites

Define 'number of months'. How many months between September 1 and October 31? How many months between September 30 and October 1?
##### Share on other sites

Sorry,

How many months between January 2005 and September 2006.

The months will be between whole months, not particular dates.

Rich
##### Share on other sites

This would work:
[code]
<?php
\$curr_year = date('Y');
\$curr_month =date('m');
\$old_year = 2004;
\$old_month = 8;
\$months_passed = (\$curr_year-\$old_year)*12+\$curr_month-\$old_month;
echo \$months_passed;
?>
[/code]

Purely based on calendar months.
##### Share on other sites

Perfect, thanks  :)
##### Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.