[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to calculate date relative to another date?

From: Egmont Koblinger
Subject: Re: How to calculate date relative to another date?
Date: Thu, 23 May 2019 09:59:11 +0200


> Every piece of the adjustment can be positive or negative, so you have to
> specify "ago" if you mean ago (unlike in natural language):
>   $ date; date --date='4 years ago 11 months ago 3 days ago 4 hours ago 7 
> minutes ago'

Another thing to note about the grammar: somewhat counterintuitively
you _cannot_ use the + or - math operators. Misleading example (with

date -d '2019/01/01 09:00:00 + 1 hour'
Tue  1 Jan 10:00:00 CET 2019

Looks good, but it's a mere accident, which becomes obvious with other units:

date -d '2019/01/01 09:00:00 + 3 seconds'
Tue  1 Jan 07:00:01 CET 2019

According to the grammar, "+ 1" or "+ 3" of these examples get parsed
as timezone specifiers (in hours), in which the given timestamp is
interpreted. Then "hour" or "seconds" gets parsed as "1 hour" or "1
second" to increment the timestamp with. Finally the result is printed
according to the +1 timezone.

In order to compute future timestamps, simply omit the "ago".


reply via email to

[Prev in Thread] Current Thread [Next in Thread]