Datetime operations with gmtmath

Salut everyone! Could you please let me know how I can, for example, add one day to the date time format using the math function keeping datetime format. The line below does not work:

gmt math -Q 2021-10-05T05:05:05 1 ADD --TIME_UNIT=d =

The desired output is 2021-10-06T05:05:05

What’s the output you got? (Maybe add -fT)

gmt math -Q -fT 2021-10-05T05:05:05 1 ADD --TIME_UNIT=d =

Beautiful! thanks a lot!

gmt math -Q -fT 2021-10-05T05:05:05 1 ADD --TIME_UNIT=d =
2021-10-06T05:05:04

Why does this command change the time from 05:05:05 to 05:05:04?

I noticed that too. If I do

gmt math -Q -fT 2021-10-05T05:05:05.00001 1 ADD --TIME_UNIT=d =

then it rounds up to 5, so it is some sort of roundoff since internally every time is a double precision days since the epoch which is at 1970. So undoing the formatting and just getting the days

gmt math -Q 2021-10-05T05:05:05 1 ADD --TIME_UNIT=d =
18906.2118634
gmt math -Q 2021-10-05T05:05:05 0 ADD --TIME_UNIT=d =
18905.2118634

they are 1 apart, but clearly breaking this down to hh:mm:ss suffers from roundoff…
Will have to debug at some point.

1 Like

Interesting. Thanks for the insight.

And if you do the math with seconds (86400) and no UNIT setting it works fine due to the smaller granularity of seconds vs days.

1 Like