Difference between two dates in months

How to be gugli friendly:

Small code to calculate the difference between two dates, in moths. Implemented in php. Note, that the start and end month is counted too.

function monthsBetweenDates($year, $month,  $yearTo, $monthTo){
 //Start and end month included in count
 return (13-$month) + ($yearTo-($year+1))*12 + $monthTo;
 }

To get the moth, and year values is up to you.

Ps: The noobiest solution would be (for example):

$year = substr(trim($date,0,4);

Ain’t i’m nice?

Azért raktam ezt most ki, mert egy csomó guglizás után se találtam erre értelmes megoldást. Ha van rá beépített fv, vagy tudsz jobbat, ott a komment.

Degradálódtam php fejlesztővé. Kedvem lenne leköpni magam… :(

Post a comment.