Sujet : Re: [OT] Unix Time Stamp - Independence Day 2025 :-)
De : jb-usenet (at) *nospam* wisemo.invalid (Jakob Bohm)
Groupes : sci.cryptDate : 12. Jul 2024, 22:45:04
Autres entêtes
Organisation : WiseMo A/S
Message-ID : <v6s853$3724b$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Epyrus/2.1.2
On 2024-06-16 22:13, Cri-Cri wrote:
On Sun, 16 Jun 2024 09:43:19 +0200, Stefan Claas wrote:
I wonder what else can be done with the Linux 'date'
command. :-)
Well, I suppose only one's imagination puts any barriers on that. I'm sure
there are ways to, if not by date alone, so by combining date with other
commands to get what you want.
Any ideas how to solve calculating the difference between two dates and
report back years, months and days, like an age of some thing, or a
person?
Like I bought my car on 2015-07-23, how old is it today? And how old will
it be on 2026-07-23?
That type of thing.
Example:
https://www.timeanddate.com/date/timeduration.html
I have a Python gadget that follows how that site does it, by excluding
the end date:
$ sky -d2age "1970-01-01--2024-06-16"
54 years, 5 months and 15 days.
$ sky -d2age "1976-02-29--2024-06-16"
48 years, 3 months and 18 days.
(In reality, since start year is a leap year, age is 12.0 years.)
I should really clean that result up a bit. :)
# Beware that this shows one month too many, 1 month old is shown
# as 02 (February) etc. Also it doesn't count the specific month
# boundaries crossed, just how far into a typical year the excess
# days will go.
# The values below count age of the example car on the day this is
# run under a modern shell like GNU bash, converting to pure
# Bourne shell will need variables and extra programs like expr
# and printf
# The date program is assumed to be the one from the GNU project.
date -u '+%y years %m months %d days %H:%M:%S' \
-d @$(( ( ( $(date '+%s') - $(date -d "2015-07-23" '+%s') ) \
/ 86400 ) * 86400 + $(date -d '1999-12-31' '+%s') ))
Enjoy
Jakob
-- Jakob Bohm, CIO, Partner, WiseMo A/S. https://www.wisemo.comTransformervej 29, 2860 Søborg, Denmark. Direct +45 31 13 16 10This public discussion message is non-binding and may contain errors.WiseMo - Remote Service Management for PCs, Phones and Embedded