![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get the Previous month in Korn Shell | nvuradi | Shell Programming and Scripting | 1 | 03-19-2008 12:31 AM |
| How to find the first day of previous month in unix? | mohapatra | Shell Programming and Scripting | 10 | 07-02-2007 09:57 PM |
| Specify a previous date as start date in shell script | ritzwan0 | Shell Programming and Scripting | 2 | 09-25-2006 06:58 PM |
| How to get previous month files | savitha | Shell Programming and Scripting | 7 | 03-23-2006 05:16 AM |
| file name using previous month | beilstwh | Shell Programming and Scripting | 1 | 08-04-2004 05:21 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|