Jump to content

Months in selected date range.


girish.kc

Recommended Posts

I am working on a report generation. Here I need to count the number of months involved in the selected date range. I need to apply the monthly charges accordingly.

 

Example: If the user selects 25-08-2011 to 03-10-2011, it should return 3 as the number of months.

 

Yes, the number of days are less than 60 but still the date range is spread across 3 months.

 

Any solution.. Please.

 

Girish

Link to comment
https://forums.phpfreaks.com/topic/248629-months-in-selected-date-range/
Share on other sites

With a little bit thinking I came up with this function:

 

function count_months($date_from, $date_to) {
   return round((strtotime('last day of this month', strtotime($date_to)) - strtotime('first day of this month', strtotime($date_from))) / 2629743.83);
}

echo count_months('25-08-2011', '03-10-2011');

Archived

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

×
×
  • Create New...

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.