Results 1 to 4 of 4
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 ...
- 03-30-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 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
- 03-30-2009 #2Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
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?
- 03-30-2009 #3Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
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.
- 03-30-2009 #4Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
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:
Edit: Actually the above doesn't work. This does:Code:date --date="`date +%b` 15 1 month ago" +%b
Code:date --date="`date +%Y-%m`-15 1 month ago"


Reply With Quote