Team,
Can someone help find code for below.. Unix: how to get a count of number of days from a given date like 10Dec2022 to today.
Looking for Answer: 102 as of (22Mar2023)
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityTeam,
Can someone help find code for below.. Unix: how to get a count of number of days from a given date like 10Dec2022 to today.
Looking for Answer: 102 as of (22Mar2023)
If you need to fetch the number of days since the start of the year for given date:
GNU
date
:$ date -d '10Dec2022' +%j
$ perl -MTime::Piece -sE '
say Time::Piece->strptime($date, "%d%b%Y")->strftime("%j")
' -- -date="10Dec2022"
344
%j
starts at 1 on January 1st 00:00:00, so strictly speaking, it's more like one plus the number of days since the start of the year.
Mar 22 at 7:48
If it's about getting the number of days since that date, with ddiff
from dateutils
(sometimes called dateutils.ddiff
):
$ date +%F
2023-03-22
$ dateutils.ddiff -i %d%b%Y 10Dec2022 now
102
That's independent of the current time of the day. 0 would be reported from 00:00 to 23:59 local time on 2022-12-10 and increments at midnight.