I’m a bit stuck with the DateInterval class of PHP. What I really want is the number of seconds elapsed between two DateTime stamps.
$t1 = new DateTime( "20100101T1200" );
$t2 = new DateTime( "20100101T1201" );
// number of seconds between t1 and t2 should be 60
echo "difference in seconds: ".$t1->diff($t2)->format("%s");
Yet all I get is zero. Is the DateInterval class not suited for arithmetic? How can I get the ‘exact’ number of seconds (or hours, or whatever) between two time stamps?
If you just want the seconds quickly you might aswell use
Your code returns 0, because the actual seconds difference is 0, the difference in your example is 1 minute (1 minute, 0 seconds). If you print the %i format, you will get 1, which is the correct diff of
$t1and$t2.