![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help, I need to get the last date of previous month | sirrtuan | Shell Programming and Scripting | 11 | 10-14-2008 02:59 AM |
| last month end date | vanathi | UNIX for Advanced & Expert Users | 7 | 03-21-2008 01:17 PM |
| Use date command to find last month | Cbish68 | Shell Programming and Scripting | 5 | 08-10-2007 07:32 AM |
| find out month from a date | rudoraj | UNIX for Dummies Questions & Answers | 5 | 07-03-2007 05:21 AM |
| how to get month last date in unix | rajan_ka1 | Shell Programming and Scripting | 12 | 10-04-2005 04:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Formatting Date (adding a month)
i need to write a script that outputs a file with the following format used for its name BRHYYYYMM.TXT. I have no problems creating this file with the current year and month in the title but i would like the month to be the next period i.e. instead of BRH200601.TXT id like BRH200602.TXT. Im unable to pass parameters into the script as its a registered financials appliction script.
Currently have - LOCFNAME="BRH`date '+%Y%m'.TXT" How do i add 1 to the month? i also need to keep it as 2 digits regards dave |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
something better than this should be there,
Code:
# !/usr/bin/ksh m=`date +%m` m=$(($m + 1)) if [ $m -lt 10 ] then m=0$m fi file="BRH`date +%Y`$m.TXT" echo $file exit 0 Last edited by matrixmadhan; 01-18-2006 at 06:47 AM. |
|
#3
|
||||
|
||||
|
matrixmadhan, what would happen if the month is Dec ?
Code:
#! /bin/ksh
typeset -Z2 M
M=$(date +%m)
Y=$(date +%Y)
if [ $M == 12 ] ; then
M=01
Y=$(($Y+1))
else
M=$(($M + 1))
fi;
file="BRH$Y$M.TXT"
echo $file
|
|
#4
|
|||
|
|||
|
i should have kept the sentinels in mind ... but didnt
good catch vino, Code:
# !/usr/bin/ksh m=`date +%m` y=`date +%Y` if [ $m -eq 12 ] then y=$(($y + 1)) m=0 fi m=$(($m + 1)) if [ $m -lt 10 ] then m=0$m fi file="BRH$y$m.TXT" echo $file exit 0 |
|
#5
|
|||
|
|||
|
Thanks for the sharp response chaps very much appreciated.
Regards Dave |
|||
| Google The UNIX and Linux Forums |