I've got the following code, but this gives me whole numbers:
<?php
$datetime1 = new DateTime('2009-10-11 00:00:00');
$datetime2 = new DateTime('2009-10-11 00:00:10');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
?>
How do I count days and show the decimal points to? In the example above, there is a difference of 10 seconds, how do I get it to display 0.000000something days?
Why not use strtotime?
$oneDay = 24 * 60 * 60;
$datetime1 = strtotime('2009-10-11 00:00:00');
$datetime2 = strtotime('2009-10-11 00:00:10');
$interval = $datetime2 - $datetime1; // seconds
$days = $interval / $oneDay; // fractions of days
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments