Bug 439956 - "date -d last-month" doesn't show the correct result
"date -d last-month" doesn't show the correct result
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: coreutils (Show other bugs)
5.0
i386 Linux
medium Severity low
: rc
: ---
Assigned To: Ondrej Vasik
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-03-31 23:17 EDT by Winston Li
Modified: 2008-04-01 01:58 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-04-01 01:58:18 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Winston Li 2008-03-31 23:17:40 EDT
Description of problem:
Command: 
date -d last-month +%Y%m 
date -d next-month +%Y%m
doesn't return the correct result on March 31, 2008


Version-Release number of selected component (if applicable):
coreutils-5.97-12.1.el5


How reproducible:
It can be reproduced.

Steps to Reproduce:
1.Change the system date to March 31, 2008
# date 0331010108
Mon Mar 31 01:01:00 CST 2008
2.run command: date -d last-month +%Y%m
result: 200803
3.run command: date -d next-month +%Y%m
result: 200805
  
Actual results:


Expected results:
200802
200804

Additional info:
Change the date to March 30, 2008, next-month reports the correct result, but
last-month doesn't.
Change the date to May 31, 2008, the results are incorrect either.
Comment 1 Ondrej Vasik 2008-04-01 01:58:18 EDT
Sorry, that's not a bug, but expected behaviour and in fact frequently asked
question. Last month works like: 2008 03 31 - 1 month = 2008 02 31 -> invalid
date -> change it to valid date -> 2008 03 02 -> that's the output
          Next month works like: 2008 03 31 + 1 month = 2008 04 31 -> invalid
date -> change it to valid date -> 2008 05 01 -> that's the output

This behaviour is expected and can't be changed. 

For details and way how to get correct month if you need, you could see
coreutils documentation , section 27.6, Relative items in date strings
(here is online version:
http://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html
)

Closing NOTABUG.

Note You need to log in before you can comment on or make changes to this bug.