Here's my code for subtracting a time...but the problem here its not subtracting also the seconds..
fldFullTime and fldTotalDuration are came from in my database..
Assuming the fldFullTime is 10:00:00
then for fldTotalDuration is 08:30:00
$fulltime = new DateTime($row['fldFullTime']);
$totalduration = new DateTime($row['fldTotalDuration']);
$res= $fulltime ->diff($totalduration);
echo "DIFF: ".$res->format("%H:%S");
The result the I get for this code is 01:00
So, when I subtract the fldFullTime [10:00:00] to fldTotalDuration [08:30:00] the result should be is 1:30:00
How can I make it?
Thanks for the help
You're using a wrong format string :
%H : hours%S : secondsYou need to add minutes :
$fulltime = new DateTime('10:00:00');
$totalduration = new DateTime('08:30:00');
$res= $fulltime ->diff($totalduration);
echo "DIFF: ".$res->format("%H:%S");
//DIFF: 01:00
echo "DIFF: ".$res->format("%H:%I:%S");
//DIFF: 01:30:00
check this :
$fulltime = new DateTime('10:00:00');
$totalduration = new DateTime('08:30:00');
$res= $fulltime ->diff($totalduration);
echo "DIFF: ".$res->format("%H:%I:%S");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With