The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-18-2006
Registered User
 

Join Date: Jan 2006
Posts: 7
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
Reply With Quote
Forum Sponsor
  #2  
Old 01-18-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
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.
Reply With Quote
  #3  
Old 01-18-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
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
Reply With Quote
  #4  
Old 01-18-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
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
Reply With Quote
  #5  
Old 01-18-2006
Registered User
 

Join Date: Jan 2006
Posts: 7
Thanks for the sharp response chaps very much appreciated.

Regards

Dave
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0