Jump to content

Archived

This topic is now archived and is closed to further replies.

HuggieBear

*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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.