Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Conversion in a ksh script

Status
Not open for further replies.

rkrug

IS-IT--Management
Mar 8, 2001
1
US
How can I create a variable that will contain the value of LASTWEEK, where lastweek is 7 days prior to today and is in the format of MM-DDD-YY (ie. 01-JAN-02)? The other question is how do I get the variable to correctly compute the date when LASTWEEK is the month prior to the current month? ie. LASTWEEK = TODAY - 7
26-DEC-01 = 02-JAN-02 - 7

 
You can use a simple shell script like:

#!/sbin/sh
# dt.sh

TZ=$TZ+`expr 24 \* 7`
export TZ

LASTWEEK=`date +%d-%b-%y`

echo $LASTWEEK
# End of dt.sh

I change date to 02-Jan-2002 for tes purpose ...

#date 0102222202
Wed Jan 2 22:22:00 WET 2002
# ./dt.sh
26-Dec-01
# date
Wed Jan 2 22:25:45 WET 2002

Regards,

Carlos Almeida,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top