Calculating difference in days using PHP Interval Object?

yonderhead

New Member
I've already seen some answers in StackOverflow about how to calculate difference in time between two dates. But no answer are using the DateTime obejct or the Interval Object in PHP. I got the following code snippet from PHP Manual website: http://www.php.net/manual/en/dateinterval.format.php.\[code\]<?php$january = new DateTime('2010-01-01');$february = new DateTime('2010-02-01');$interval = $february->diff($january);// %a will output the total number of days.echo $interval->format('%a total days')."\n";// While %d will only output the number of days not already covered by the// month.echo $interval->format('%m month, %d days');?>\[/code\]But the problem is that total days equals 6015 days when it should only be 31 days. I tried to access the instance variable days in the Interval object. It too shows 6015 days. But the instances for month and days intervals are correct. Can someone tell me why?And I want to use these objects to calculate the difference in times!Many thanksUPDATE:I think it was just a problem with my PHP setup
 
Back
Top