Operating System - HP-UX
1753797 Members
7131 Online
108799 Solutions
New Discussion

Re: Get the month 2 months ago

 
SOLVED
Go to solution
dhman
Occasional Advisor

Get the month 2 months ago

I have found following:

prevmonth=`perl -MPOSIX=strftime -le '@t = localtime; $t[3] = 1; $t[4]--;print strftime("%b", @t)'`

This will return the previous month.

I want the month 2 months ago. For instance now it is December. Above will return me "Nov". I want it to return "Oct". What changes do I have to make on the above? I can't figure it out.

Thanks

2 REPLIES 2
Hans_c
Occasional Advisor
Solution

Re: Get the month 2 months ago

I had luck by manipulating the $t[4] section:

 perl -MPOSIX=strftime -le '@t = localtime; $t[3] = 1; $t[4] -= 2;print strftime("%b", @t)'
Oct

perl -MPOSIX=strftime -le '@t = localtime; $t[3] = 1; $t[4] -= 3;print strftime("%b", @t)'
Sep

Hope this helps!

dhman
Occasional Advisor

Re: Get the month 2 months ago

Thank you very much.