tag 15752 notabug
thanks

On 10/29/2013 07:58 PM, Andy Lamb wrote:
> Hello,
> 
> February of 2013 does not work, it comes up with March twice!
> 
> /bin/date --date=-6 month +%b%Y = Apr2013
> /bin/date --date=-7 month +%b%Y = Mar2013
> /bin/date --date=-8 month +%b%Y = Mar2013
> /bin/date --date=-9 month +%b%Y = Jan2013

This is a FAQ:

https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e

Subtracting by months is fuzzy (does it mean multiples of 28, 29, 30, or
31 days?  What is one month after Oct 31, Nov 30 or Dec 1?).  Daylight
Savings doesn't help (even if I subtract an exact multiple of days,
there are cases where a timezone could cause a multiple of 24 hours to
bypass a 23-hour day or get trapped by a 25-hour day).  You are best off
trying to start from a middle of a month to guarantee that even with the
fuzz you still land in the desired destination.

$ date --date="$(date "+%b 15") -6 month" +%b%Y
Apr2013
$ date --date="$(date "+%b 15") -7 month" +%b%Y
Mar2013
$ date --date="$(date "+%b 15") -8 month" +%b%Y
Feb2013
$ date --date="$(date "+%b 15") -9 month" +%b%Y
Jan2013

As such, I'm closing this as not a bug, although you may feel free to
add further comments.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to