How to show last month date?

Hi Guys,

Please somebody give me a hand to show the Month & Year in assigning to a variable and with format "MMMYY" (i.e. Jul11). See below preferred output.

I tried using this but it is giving me the current month...

date = "`date +%b%y`"
Aug11

DESIRED OUTPUT:

Jul11

Thank in advance.

Br,
pinpe

with GNU date

$ date --date '1 month ago' '+%b%d'
Jul05
$
$ date --date '1 month ago' '+%b%y'
Jul11
$

Hi anchal_khare,

Thanks for the reply but I'm using UNIX OS. The command you gave me is giving me errors as shown below...

root@hostname>date --date '1 month ago' '+%b%d'
date: illegal option -- date
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

Br,
pinpe

Well in that case, you should have a look at the FAQS section. lots of date calculations related threads are available with solutions.

also look at the Perderabos datecalc