|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
I'm writing a shell script in unix about incrementing date. I want to increment the month of the current date whose format is `date +%b%Y`. So today the current date is May2004, i want the output to be Jun2004 and so if the current date is Dec2004, the output will be Jan2005. Need your advise asap. Thnx in advance. |
|
#2
|
|||
|
|||
|
#!/bin/ksh
getNextMonth() { aMonth=$(echo $1 | cut -c1-3); yr=$(echo $1 | cut -c4-) months=$(cal $yr | grep "[A-Z][a-z][a-z]") i=1; n=$(for mon in $months; do [[ "$mon" = "$aMonth" ]] && echo $i || (( i += 1 )); done) [[ "$n" -eq 12 ]] && n=1 && (( yr += 1 )) || (( n += 1 )) echo "$(echo $months | cut -d" " -f$n)$yr" } # test next month function ---------------------------------------------- for mmmdd in May2004 Dec2004 Jan2004 Mar2004 Aug2004 Dec2009 do echo "in = $mmmdd \nout = $(getNextMonth $mmmdd)" done |
|
#3
|
|||
|
|||
Thanks so much mcq1 for the script, it's now working. 'Til my next script problem ok, tc. |
|
#4
|
|||
|
|||
|
how to increment month in asp can anybody help me???????
i m in big trouble.. plz!!!!!!!!!! mn=month(fnsdt) mn1=mn+1 or directly i have done that increment but still it is not working, bar="1"&"/"&Monthname(month(fnsdt)+1)&"/"&year(fnsdt) |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > increment month of date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|