total of months in 1 year

in my db, i have
date start = August 16, 2007
date end = August 15, 2008
now i would to how to get the number of months between that 2 dates

tnx n advance :wink:

so u want every month to be count?
so ur example would return 13, because August is counted twice?

what i would do is:
[php]
//preset data:
$day_start=16;
$month_start=8;
$year_start=2007;

$day_end=15;
$month_start=8;
$year_start=2008;

//make them a timestamp
$time_start=mktime(12,0,0,$month_start,$day_start,$year_start)
$time_end=mktime(12,0,0,$month_end,$day_end,$year_end)

//month since 1.1.0000
$totalmonth_start=date(ā€˜nā€™,$time_start)+$year_start12;
$totalmonth_end=date(ā€˜nā€™,$time_end)+$year_end
12;

//calculate the difrence
$result=$totalmonth_end-$totalmonth_start+1;

//of cause this can be written in one statement:
$result=(date(ā€˜nā€™,mktime(12,0,0,8,16,2007))+200712)
-(date(ā€˜nā€™,$mktime(12,0,0,8,15,2008))+2008
12);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service