Date command bug?

silver.bullet at zoho.com silver.bullet at zoho.com
Mon Aug 31 20:21:32 UTC 2015


On Mon, 31 Aug 2015 21:00:48 +0200, Johnny Rosenberg wrote:
>So my question is: Why does the followinghappen?
>~$ date +%F
>2015-08-31

Because September the 31th doesn't exist, it's October the 1st.

[rocketmouse at archlinux ~]$ info date | grep fuzz -A12
‘month’ for moving by whole years or months.  These are fuzzy units, as
years and months are not all of equal duration.  More precise units are
‘fortnight’ which is worth 14 days, ‘week’ worth 7 days, ‘day’ worth 24
hours, ‘hour’ worth 60 minutes, ‘minute’ or ‘min’ worth 60 seconds, and
‘second’ or ‘sec’ worth one second.  An ‘s’ suffix on these units is
accepted and ignored.

   The unit of time may be preceded by a multiplier, given as an
optionally signed number.  Unsigned numbers are taken as positively
signed.  No number at all implies 1 for a multiplier.  Following a
relative item by the string ‘ago’ is equivalent to preceding the unit by
a multiplier with value -1.

--
   The fuzz in units can cause problems with relative items.  For
example, ‘2003-07-31 -1 month’ might evaluate to 2003-07-01, because
2003-06-31 is an invalid date.  To determine the previous month more
reliably, you can ask for the month before the 15th of the current
month.  For example:

     $ date -R
     Thu, 31 Jul 2003 13:02:39 -0700
     $ date --date='-1 month' +'Last month was %B?'
     Last month was July?
     $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
     Last month was June!

[rocketmouse at archlinux ~]$

https://duckduckgo.com/html?q=linux+date+next+month&t=gnu
http://stackoverflow.com/questions/13168463/using-date-command-to-get-previous-current-and-next-month





More information about the ubuntu-users mailing list