tags:

views:

59

answers:

2

Hi, what is the shortest way to calculate the difference in months (average num of days in a month as 30) between two unix timestamps? Date::diff is available for working with DateTime objects, but I'm wondering if there's a neat way to work this out with timestamps...

A: 

Well, 30 days are 60*60*24*30=2592000 seconds, so just divide the difference with that number:

(endTime - startTime) / 2592000
aioobe
A: 

I agree with the solution above but it remains inaccurrate. You better use the DateTime object; you can load it with your Unix TimeStamps like this:

$dateTime->setTimestamp( $stamp );
Gabor de Mooij