Archive

Why am I getting an Invalid result in span between two dates?

Contributor

This code:

   | makeresults
   | eval StartTime = strptime("2018-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
   | eval EndTime = strptime("2018-01-01 00:10:00", "%Y-%m-%d %H:%M:%S")
   | eval Elapsed = EndTime - StartTime
   | fieldformat Elapsed = strftime(Elapsed, "%H:%M:%S")

results to Elapsed=08:10:00 or eight hours and ten minutes, instead of just ten minutes.

Would like to get some assistance on why this happens and how to fix. Thanks a lot!

0 Karma
1 Solution

Champion

The function calculates 600 seconds as the epoch time.And time zones are also included.

Epoch Time:600
↓With the time zone added:JST
1970-01-01 09:10:00

Try this!
| fieldformat Elapsed = tostring(Elapsed, "duration")

View solution in original post

Champion

The function calculates 600 seconds as the epoch time.And time zones are also included.

Epoch Time:600
↓With the time zone added:JST
1970-01-01 09:10:00

Try this!
| fieldformat Elapsed = tostring(Elapsed, "duration")

View solution in original post

Contributor

Wizardry! | fieldformat Elapsed = tostring(floor(Elapsed), "duration")

Thanks a lot

0 Karma