Date command bug?
Johnny Rosenberg
gurus.knugum at gmail.com
Mon Aug 31 19:00:48 UTC 2015
I have a script that does something if it's the last day of the month. To
calculate the last day of the month I first used the following line that I
”stole” from somewhere:
LastDayOfMonth=$(date -d"-1 day 1 $(date -d'next month' +%b)" +'%d')
In this case, LastDayOfMonth should be 31 since it is August now, but it
fails in two ways:
”$(date -d'next month' +%b)” returns ”okt”, since my locale is Swedish
(October=oktober in Swedish, with all non-capital letters unless it's at
the beginning of a sentence).
So I changed the whole line to:
LastDayOfMonth=$(date -d"-1 day 1 $(date -d'next month' +%F)" +'%d')
”date -d'next month' +%F” returns ”2015-10-01” which at least doesn't lead
to an error, but this is still the second way everything fails: Next month
is September, not october!
So my question is: Why does the followinghappen?
~$ date +%F
2015-08-31
~$ date -d'next month' +%F
2015-10-01
~$
Wouldn't rather the following happen?
~$ date +%F
2015-08-31
~$ date -d'next month' +%F
2015-09-01
~$
I can probably get around the problem altogether, but I still want to know
of this is a bug or not, and if not, why…
Kind regards
Johnny Rosenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20150831/21204d9c/attachment.html>
More information about the ubuntu-users
mailing list