You are not logged in.

#1 2024-08-16 00:50:40

marens
Member
From: World without M$
Registered: 2023-02-02
Posts: 872

The difference between dates

The date command is very useful.
In this case, it is necessary to calculate  the difference  date2  -  date1.

This could be an interesting example:

date1
The 1984 Summer Olympics (Los Angeles) closed August 12, 1984.
https://en.wikipedia.org/wiki/1984_Summer_Olympics

date2
The 2028 Summer Olympics (Los Angeles) opening July 14, 2028.
https://en.wikipedia.org/wiki/2028_Summer_Olympics

Let's  calculate  how much time will pass between  these dates.

Notes *
The date  command will use the time in seconds.
A day lasts 86400 seconds  (24 hours * 60 minutes * 60 seconds).

Difference in days:

$ echo $((($(date +%s -d 20280714) - $(date +%s -d 19840812)) / 86400))
16042

Or with python3:

$ python3 -c 'from datetime import date; print (date(2028,7,14)-date(1984,8,12))'
16042 days, 0:00:00

There are many great scripts (bash, python) that you can easily find, but they all work on a similar basis.


If people would know how little brain is ruling the world, they would die of fear.

Offline

#2 2024-08-16 02:58:22

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,026

Re: The difference between dates

Been using date in conkys for years.

My mistake: dateutils for years

Last edited by Sector11 (2024-08-16 03:02:32)


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#3 2024-08-16 08:26:20

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: The difference between dates

dateutils can make life simpler:

dateutils.ddiff 1984-09-12 2028-07-14
16011
dateutils.ddiff 1984-09-12 2028-07-14 -f '%Y years %m months %d days'              
43 years 10 months 2 days

Offline

#4 2024-08-16 14:07:43

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,026

Re: The difference between dates

brontosaurusrex wrote:

dateutils can make life simpler:

dateutils.ddiff 1984-09-12 2028-07-14
16011
dateutils.ddiff 1984-09-12 2028-07-14 -f '%Y years %m months %d days'              
43 years 10 months 2 days

Exactly how I use it in conky.

For example Quit Smoking:

S11: 08-06-09:${color0}${pre_exec dateutils.ddiff 2009-06-08 'today' -f ' %y·%m·%d'}${color}

Displays
24-08-16-111719.jpg
It's great for Birthdays, Anniversaries, etc. - I'm always forgetting those.

If you look for a future date the result has a " - " in front of it.

NOTE:
Debian requires 'dateutils.diff' other distros may only require 'dateutils'


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#5 2024-08-16 14:22:26

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,694

Re: The difference between dates

Sector11 wrote:

Exactly how I use it in conky.

I also use dateutils in conky's. I learned that from you once.  wink

Edit: here in siduction there is no dateutils-diff, only dateutils

Last edited by unklar (2024-08-16 14:33:38)

Offline

#6 2024-08-16 14:25:25

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,026

Re: The difference between dates

unklar wrote:
Sector11 wrote:

Exactly how I use it in conky.

I also use dateutils in conky's. I learned that from you once.  wink

We have learned a lot from each other over the years.
Shared and grown - together.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#7 2024-08-17 03:03:44

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,652
Website

Re: The difference between dates

unklar wrote:

here in siduction there is no dateutils-diff, only dateutils

There's no package called dateutils-diff anywhere, it's dateutils you have to install.
'dateutils.ddiff' is one of the commands it provides.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#8 2024-08-17 19:09:40

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,026

Re: The difference between dates

RE: dateutils

A long time ago when I started checking out dateutils I found that the commands did not work in Debian as seen from various sites on the internet,
Then I came across a site that stated in Debian the command must be prefixed with "dateutils." ← note the dot or period

so

ddiff

became

dateutils.ddiff

fresse org - datediff command
- talks about

$ datediff ...

Ubuntu Manpages - ddiff
- talks about

$ ddiff ...

GitHub for dateutils
- talks about

$ datediff ...

Debian manpaged for dateutils
- talks about

$ ddiff ...

in the examples - scroll down
- - but that doesn't work
Now look at the "url" on the top line on that page, see that: dateutils.ddiff
- that works
In my terminal:

 2024·08·17 @ 15:31:12 ~
   $ dateutils.ddiff 2009-06-08 'today' -f ' %y·%m·%d'
 15·2·9
 
 2024·08·17 @ 15:33:07 ~
   $ ddiff 2009-06-08 'today' -f ' %y·%m·%d'
bash: ddiff: command not found
 
 2024·08·17 @ 15:33:14 ~
   $ datediff 2009-06-08 'today' -f ' %y·%m·%d'
bash: datediff: command not found
 
 2024·08·17 @ 15:33:44 ~
   $ 

As John and I said: same program dateutils
- different ways to use it in different distros.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#9 2024-09-26 12:47:51

Colonel Panic
Member
Registered: 2018-11-13
Posts: 1,429

Re: The difference between dates

Good thread, I've just downloaded dateutils now.

Offline

#10 2024-09-26 13:52:44

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,026

Re: The difference between dates

Enjoy.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

Board footer

Powered by FluxBB