Help needed on Date command

Hi,

I am facing one problem with date command.Actually I want to use this command to get the last month,not the current month..OK,I can do current month - 1 and give special condition for january,But this time i need last month as strings like January,februaury,march etc...
There is option available to get the month in the string form and that is
`date +%B` but this will give you the current month.
I can definitely do what i want with 12 cases one for each month but i want to avoid that.Please help me if anyone has any idea to implement this with out using 12 conditions.

Thanks,
-Nikunj

http://www.unix.com/showthread.php?t=13785

Perderabo's datecalc script is what you need to look at.

get your self gnu date if you do not have it already. it actualy makes a readable script.

date
Fr Jul 7 17:47:56 CEST 2006

date -d"1 month ago"
Mi Jun 7 17:48:21 CEST 2006

since i learned about this some year ago i drop all date hacks (do you know what you can do with $TZ ? :slight_smile:

Thanks grumpf,
Actaully i was looking for some similar options if i could..But the problem is I am using SunOs 5.8 and i am not authorized to add any package to the server.I tried this command and it didn't work..
It seems you have done lot of stuff on date command,Can you tell me is there any way to use date command to read from some variable not from the system,I mean if i can give my inputs to date command with out disturbing any system configurations?

Thanks in advance..

One way of doing it is with an array.

set -A YEAR January February March April May June July August September October November December

MONTH=$(date +%m)

if (( ${MONTH} == 1 )); then
MONTH=11
else
let MONTH=${MONTH}-2
fi

echo "This month is July, so last month was "${YEAR[${MONTH}]}

Thanks System Shock,

It seems it is the best way to do,I didn't know that we can have array too in a shell script,Thank you very much to make me aware of this.