Bug 457370 - date -d 'last month' returns this month
date -d 'last month' returns this month
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: coreutils (Show other bugs)
All Linux
low Severity low
: rc
: ---
Assigned To: Ondrej Vasik
Depends On:
  Show dependency treegraph
Reported: 2008-07-31 04:13 EDT by Rafal Wijata
Modified: 2008-08-04 06:15 EDT (History)
0 users

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

Attachments (Terms of Use)

  None (edit)
Description Rafal Wijata 2008-07-31 04:13:22 EDT
Description of problem:
# LANG=C date
Thu Jul 31 10:00:21 CEST 2008
# LANG=C date -d 'last month'
Tue Jul  1 10:00:27 CEST 2008

Version-Release number of selected component (if applicable):
All, F8 as well.

Actual results:
30 days before today

Expected results:
last month, like in perl
# perl -e 'use DateTime; print DateTime->now;'
# perl -e 'use DateTime; print DateTime->now->subtract(months => 1);'

or pgsql
template1=# select now();
 2008-07-31 10:12:21.004549+02

template1=# select now() - interval '1 month';
 2008-06-30 10:12:22.249536+02

PS: I know it's not directly RH related, but I don;t know where else to post it.
Comment 1 Ondrej Vasik 2008-08-04 06:15:24 EDT
Thanks for report, that fuzzy behaviour was already reported few times... However - that's not a bug, but documented behaviour which is expected. "Last month" is relative time offset which represents -1 month. For Jul 31, it substracts one month from the date - so the result should be Jun 31. That date is invalid, so it is intentionally interpreted as Jul 1. It is documented in RHEL-5 coreutils (date) info documentation, section 27.6 Relative items in date strings. Solution for scripts is also available in that documentation. Closing NOTABUG.

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