dateutils icon indicating copy to clipboard operation
dateutils copied to clipboard

How to take difference between now and today at a certain time or tomorrow at a certain time

Open arooni opened this issue 5 years ago • 4 comments

[I] ✘  ~/bin  dateutils.ddiff now tomorrow -f '%H hours, %M minutes, %S seconds.' 24 hours, 0 minutes, 0 seconds.

[I] ~/bin  dateutils.ddiff now 2018-10-12T8:00:00 -f '%H hours, %M minutes, %S seconds.' 11 hours, 55 minutes, 15 seconds.

[I] ~/bin  dateutils.ddiff now tomorrowT8:00:00 -f '%H hours, %M minutes, %S seconds.' ddiff: cannot make sense of `tomorrowT8:00:00' using the given input formats

today, now, and tomorrow work .. but is there a way to specify a specific time so i can get an hour, minute, seconds output?

I know I could run [I] ~/bin  dateutils.ddiff now 2018-10-12T8:00:00 -f '%H hours, %M minutes, %S seconds.' 11 hours, 54 minutes, 51 seconds.

but I'm hoping not to have to specify the date by hand, and was hoping to append a specific time to today/tomorrow. thanks!

arooni avatar Oct 11 '18 20:10 arooni

Well, I don't know if it's helpful but there's also time:

$ dateutils.ddiff time 14:00:00
23430s

which contrasts the current time to the time specified. Now if you guarantee that you mean tomorrow at that time, you could add 86400 seconds to the output but then again you could have just written:

$ dateutils.ddiff now `dateutils.dconv tomorrow`T14:00:00
109644s

which uses your shell's substitution capabilities and, because of two independent invocations, suffers from a race condition at around midnight.

hroptatyr avatar Oct 12 '18 07:10 hroptatyr

that works! thanks!

also; anyway to get distance between now and end of month (or beginning of next month)? i don't see it on the man page under " DATE/TIME can also be one of the following specials

   DATE/TIME can also be one of the following specials
     - `now'           interpreted as the current (UTC) time stamp
     - `time'          the time part of the current (UTC) time stamp
     - `today'         the current date (according to UTC)
     - `tomo[rrow]'    tomorrow's date (according to UTC)
     - `y[ester]day'   yesterday's date (according to UTC)

"

arooni avatar Oct 16 '18 17:10 arooni

No, there are no specials for that but there's a much more powerful tool to achieve this: dateround (possibly available to you as dateutils.dround)

## end of month
$ dateutils.dround today +31
## first of next month
$ dateutils.dround today +1

So assuming midnight on one of these events you could do:

$ dateutils.ddiff now `dateutils.dround today +31`T00:00:00
1183630s

Similarly for first of next month.

hroptatyr avatar Oct 17 '18 07:10 hroptatyr

thanks -- that worked great!

may today be the best day of your life,

david parkinson founder - aroonilabs.com blog - brofist.com twitter - @brofist https://twitter.com/brofist

On Wed, Oct 17, 2018 at 2:13 AM Sebastian Freundt [email protected] wrote:

No, there are no specials for that but there's a much more powerful tool to achieve this: dateround (possibly available to you as dateutils.dround)

end of month

$ dateutils.dround today +31

first of next month

$ dateutils.dround today +1

So assuming midnight on one of these events you could do:

$ dateutils.ddiff now dateutils.dround today +31T00:00:00 1183630s

Similarly for first of next month.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hroptatyr/dateutils/issues/87#issuecomment-430516017, or mute the thread https://github.com/notifications/unsubscribe-auth/AAh-e_8hCstBhElJr4C7_NWdSuYwOFxZks5ultiSgaJpZM4XYR2w .

arooni avatar Nov 02 '18 00:11 arooni