Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    date function working wrongly on last three days of march.

    I am currently using date command to find the previous months from current month.

    I ran this command in March 30, 2009

    date --date="0 month ago" +%b
    o/p: Mar

    date --date="1 month ago" +%b
    o/p: Mar

    date --date="2 month ago" +%b

    o/p : Jan

    this command is working fine in every month except last three days of march.
    For the first two commands the o/p is same. I think this is because of some wrong logic.

    is there any fix available for this.

    I am using redhat distro.
    uname -a

    Linux dbll1bil 2.4.21-4.EL #1 Sat Dec 13 21:37:48 CST 2003 i686 athlon i386 GNU/Linux

  2. #2
    Linux Newbie
    Join Date
    Sep 2004
    Can config it's there in Fedora 8 - using date (GNU coreutils) 6.9

    Tried the OP's commands and
    date --date="-1 month" +%b
    date --date="-2 month" +%b

    get the same results.
    In a world without walls and fences, who needs Windows and Gates?

  3. #3
    I had a similar problem but with --date="1 day ago". It was the day after the time changed in the US (at least for me in the East). It moved 1 hour forward. I think that that time change is causing GNU date problems.

    Edit: Forgot to mention I'm using RHEL V4.7. Also, the problem was it gave me the date 2 days ago, not 1.

  4. $spacer_open
  5. #4
    Well I did some research and found that this may not be a problem but intended behavior. Here's the link.

    To solve your month problem using their solution the command to use is:

    date --date="`date +%b` 15 1 month ago" +%b
    Edit: Actually the above doesn't work. This does:

    date --date="`date +%Y-%m`-15 1 month ago"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts