|
Help, I need to get the last date of previous month
Hi, I'm new with Unix, I'm trying to get a last day of previous month with this format: %b %d %Y (example: Feb 25 2008).
Here is what I have so far.
#!/bin/ksh
cur_month=`date +%m`
cur_year=`date +%Y`
prev_month=$(($cur_month-1))
# Check to see if this is January
if [ $prev_month -lt 1 ]
then
prev_year=$(($cur_year-1))
prev_month=12
LastDayOfMonth=`/bin/cal $prev_month $prev_year | grep -v "^$" | tail -1 | awk '{print $NF}'`
else
LastDayOfMonth=`/bin/cal $prev_month $cur_year | grep -v "^$" | tail -1 | awk '{print $NF}'`
fi
==============================================
I can get the last date of the previous month but I don't know how to put it back into the format that I wanted. Please help.
Thank you.
|