nadeemshafi9 Posted July 29, 2009 Share Posted July 29, 2009 How can I get the enlapsed months, complete months between two timestamps (Unix timestamps)? is there any function that'll help me ? or what aproach should I use? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2009 Share Posted July 29, 2009 Except for simple comparisons, timestamps must be converted to be usable for most purposes. Because the number of days in the months are not constant, you would need to convert to years, months, days and do the math. I would take the difference in the years * 12, plus the difference in the months (subtract 1 if the end day is less-than the start day.) Untested, but should work - <?php // whole months // get the timestamps into year, month, day values using your preferred method - $start = '2008-07-29'; $end = '2009-08-29'; list($sy,$sm,$sd) = explode("-",$start); list($ey,$em,$ed) = explode("-",$end); $months = (($ey-$sy) * 12) + ($em - $sm) - ($ed < $sd); echo $months; ?> Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted July 30, 2009 Author Share Posted July 30, 2009 thanks v much, i will save teh code but my colegues say that we should use 30 day months for simplicity to calculate rate boundries etc for product usage Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.