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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Date question

Status
Not open for further replies.

pdtt

Programmer
Sep 24, 2002
35
CA
I want to assign a formatted date to a variable and then
add the date variable to the name of a log file.

This doesn't work for the assignement
RunDate= Date '+%y-%m-%d'

How would I get the variable assigment to work?

how would I create a log file name that would look like this?

# variables
RunDate=????
LogFile= "LoadLog-"
LogExtension= ".log"

#log file name I want to create
LoadLog-03-04-24.log

How do you build the single string?

Thank you
 
You might want to try:

RunDate=`date +%y-%m-%d`

where the ` are backticks (above your tab key usually), not simple apostrophes. HTH.
 
Ken,

I tried the backticks and it did not work. By the way, I don't know if it matters, I am using the korn shell.

Paul
 
Try this for your script...
[tt]
# variables
RUNDATE=$(date '+%y-%m-%d')
LOGFILE=LoadLog
LOGEXT=log

LOGFILENAME=${LOGFILE}-${RUNDATE}.${LOGEXT}

print "Log File Name: ${LOGFILENAME}"
[/tt]
This prints out...
[tt]
Log File Name: LoadLog-03-04-24.log
[/tt]
Hope this helps.

 
What KenCunningham said should work in Korn & Bourne shell

Logfile=Loadlog-`date +%y-%m-%d`.log

you need a space between the date and the +
 
Thank you Ken and Sam. The answers work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top