On Wed, 2 Feb 2005 21:59:42 +0100, "pero" <pe**@net.hr> wrote:
I have the following problem
When I subtract 2 (timestamp) dates, it reports back wrong time difference.
Can it be done like this at all?
$datee="2005-02-01 19:54:00"
$datee1="2005-02-01 18:58:00"
$date1=strtotime($object["datee"]);
$date2= strtotime($object["datee1"]);
Please post _runnable_ code - there's two parse errors and two undefined uses
of $object. Making minimal changes to your code so it runs and actually
displays something gives:
<?php
$datee="2005-02-01 19:54:00";
$datee1="2005-02-01 18:58:00";
$date1=strtotime($datee);
$date2= strtotime($datee1);
$diff=0;
$diff = $date1-$date2;
$days = round($diff/86400, 0);
$hours = round(($diff%86400)/3600, 0);
$minutes = round(($diff%3600)/60, 0);
$seconds = $diff%60;
print "days: $days<br>";
print "hours: $hours<br>";
print "minutes: $minutes<br>";
print "seconds: $seconds<br>";
?>
Output is:
days: 0
hours: 1
minutes: 56
seconds: 0
Minutes are fine, hours are not. It's because you've used round. You want
floor; 56 minutes is 0.933 hours, so you want to round down, not up.
$days = floor($diff/86400);
$hours = floor(($diff%86400)/3600);
$minutes = floor(($diff%3600)/60);
$seconds = $diff%60;
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool