Jump to content


Photo

Need help adding seconds to time


  • Please log in to reply
3 replies to this topic

#1 urbandsigns.com

urbandsigns.com
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 August 2006 - 04:43 PM

I have time (no date) in the format: 00:00:00 and I need to add a few seconds to it, how do I do this?

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 09 August 2006 - 04:49 PM

Is this what you're looking for:
<?php
$time = '13:15:07';
echo "Time: {$time}<br />"; 
$new_time = date('H:i:s',strtotime($time)+8); // adds 8 seconds
echo "New time: {$new_time}";
?>

It would generate the output:
Time: 13:15:07
New time: 13:15:15


#3 urbandsigns.com

urbandsigns.com
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 August 2006 - 05:08 PM

Thanks for the response, but this isn't adding correctly. Here is my code based on what you posted:
$total2 = date('H:i:s',strtotime($_GET["score"])+$_GET["cones"]);

Scores: 00:33:26
Cones: 39
Total2: 00:34:05

#4 urbandsigns.com

urbandsigns.com
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 August 2006 - 05:12 PM

Nevermind, just realized the the last number is seconds and not milliseconds. It is working correctly. Thanks for the help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users