0

For example, I have got the following code:

$time1 = 14:02:21;
$time2 = 12:04:48;
$time3 = 08:19:17;

$addtime = $time1 + $time2 + $time3;
echo $addtime;

Which would return 34:26:26

I am trying to do this inside of a while loop:

Before while loop:

$on_duty_time = '';

Inside of While Loop:

$on_duty_time += strtotime($row2['driving_timer']);

After the While Loop:

$on_duty_time -= strtotime('00:00:00');
$time = date('H:i:s', $on_duty_time);
echo $time;

This code worked when I had two timestamps only, which were 00:35:40 and 00:00:21 (being called in by the variable $row2['driving_timer']), which gave me the end result of 00:36:01.

But now one of my loops has the timestamp: 00:01:36, but it is returning 17:01:36 when I try to put it through my while loop code.

Any ideas on why this is happening?

Or perhaps, does anyone know of a better way to add these timestamps together whilst using a while loop?

Glavić
  • 42,781
  • 13
  • 77
  • 107
Kelsey
  • 913
  • 3
  • 19
  • 41
  • You lost me at `Which would return 34:26:26`... Say what? – Mike Jun 02 '16 at 22:19
  • Also `$time1 = 14:02:21;` is a syntax error. – Mike Jun 02 '16 at 22:20
  • Think of the times as time on a stop watch, where 17:34:02 is 17 hours, 34 minutes, and 2 seconds. – Kelsey Jun 02 '16 at 22:21
  • 18 + 12 + 14 != 34 – Mike Jun 02 '16 at 22:24
  • Stop beating around the bush and just post your actual code in a [minimal complete and verifiable way](http://stackoverflow.com/help/mcve). – Mike Jun 02 '16 at 22:27
  • @Mike My bad, meant to make it 08 not 18. – Kelsey Jun 02 '16 at 22:27
  • 2
    [How to convert `H:i:s` format to seconds?](http://stackoverflow.com/questions/4834202/convert-time-in-hhmmss-format-to-seconds-only/20874702#20874702) --- Then sum them up. --- [How to convert seconds to `H:i:s`?](http://stackoverflow.com/questions/3172332/convert-seconds-to-hourminutesecond/20870843#20870843) – Glavić Jun 03 '16 at 04:17

0 Answers0