Operating System - HP-UX
1832089 Members
2731 Online
110037 Solutions
New Discussion

Previous month date command

 
SOLVED
Go to solution
Oktay Tasdemir
Advisor

Previous month date command

Hi,

Is there a way of returning the previous months date without writing a complex script. For example if we are currently in July I would like to return the value of 06 (being June). I have looked at the date command but could not find anything suitable to my needs.
Could anyone please assist.

Many thanks
oktay
Let the fun and games begin
4 REPLIES 4
Bruno Vidal
Respected Contributor
Solution

Re: Previous month date command

Hi

do like this:
X=$((`date +%m` -1))
if [ $X -eq 0 ]; then X=12; fi
echo $X

Cheers.
Bruno Vidal
Respected Contributor

Re: Previous month date command

Hi

do like this:
X=$((`date +%m` -1))
if [ $X -eq 0 ]; then X=12; fi
echo $X

Cheers.
Bruno Vidal
Respected Contributor

Re: Previous month date command

Oups, sorry, a bit to hard on the "submit"...
Oktay Tasdemir
Advisor

Re: Previous month date command

Your a gem.

Thankyou
Let the fun and games begin