Scripting a log file name to include the current date and time.

 

At the bottom of this posting are some useful links to sites that explain how to create log files with the date and time incorporated into the file name of the log file.

The following is code I use for a UK date format.  This was originally from this posting over at Experts Exchange.

@echo off

set startDate=%date%
set startTime=%time%

echo %startDate%
echo %startTime%

set sdy=%startDate:~6%
set /a sdd=1%startDate:~0,2% – 100
set /a sdm=1%startDate:~3,2% – 100
set /a sth=%startTime:~0,2%
set /a stm=1%startTime:~3,2% – 100
set /a sts=1%startTime:~6,2% – 100

<FileName or Procedure>  > ./logs/%sdd%.%sdm%.%sdy%-%sth%.%stm%.log

Links:

Shell Scripting – CyberCiti

Coding Forums

 

Technorati Tags: ,,,,,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.