Reputation: 33439
How do I tell what year of day is today e.g. if today was Mar 1 2008, it should reply 61.
Upvotes: 1
Views: 140
Reputation: 246799
If you have GNU date,
$ date -d "Mar 1 2008" +%j
061
If you don't have GNU date, but you have a recent-ish version of Perl:
perl -MTime::Piece -le '
print Time::Piece->strptime("Mar 1 2008", "%b %e %Y")->strftime("%j")
'
Upvotes: 1
Reputation: 182629
Try the %j
format specifier:
$ date +%j
016
The standard says this about %j
:
%j
Day of the year as a decimal number [001,366].
Upvotes: 3