Computer > Programming > Batch Files
When working with MS-Windows batch file jobs, many times I need to create an output log file that will contain in its file name the specific date, time or both in its filename. In order to do this I need the filename in an environmental variable so I can fill in information using the '>>' redirectors after executing my batch commands.
I developed 3 batch files that do exactly that and here I share them with you.
Date_time_stamps.zip
date2file.cmd
Sets a date stamp to an environmental variable of your choice.
Usage:
c:>\date2file.cmd variable
Result: %variable% = YYYYMMDD
Example:
If today is 4/7/2010 then running
c:>\date2file.cmd mystamp
an environmental variable with name mystamp is created with value 20100704
time2file.cmd
Sets a time stamp to an environmental variable of your choice.
Usage:
c:>\time2file.cmd variable
Result: %variable% = hhmm
Example:
If it is run on 17:34 then
c:>\time2file.cmd mystamp
an environmental variable with name mystamp is created with value 1734
dt2file.cmd
Sets a datetime stamp to an environmental variable of your choice.
Usage:
c:>\date2file.cmd variable
Result: %variable% = YYYYMMDDhhmm
Example:
If it is run on 4/7/2010 5:23 then running
c:>\dt2file.cmd mystamp
an environmental variable with name mystamp is created with value 201007040523
When working with MS-Windows batch file jobs, many times I need to create an output log file that will contain in its file name the specific date, time or both in its filename. In order to do this I need the filename in an environmental variable so I can fill in information using the '>>' redirectors after executing my batch commands.
I developed 3 batch files that do exactly that and here I share them with you.
Date_time_stamps.zip
date2file.cmd
Sets a date stamp to an environmental variable of your choice.
Usage:
c:>\date2file.cmd variable
Result: %variable% = YYYYMMDD
Example:
If today is 4/7/2010 then running
c:>\date2file.cmd mystamp
an environmental variable with name mystamp is created with value 20100704
time2file.cmd
Sets a time stamp to an environmental variable of your choice.
Usage:
c:>\time2file.cmd variable
Result: %variable% = hhmm
Example:
If it is run on 17:34 then
c:>\time2file.cmd mystamp
an environmental variable with name mystamp is created with value 1734
dt2file.cmd
Sets a datetime stamp to an environmental variable of your choice.
Usage:
c:>\date2file.cmd variable
Result: %variable% = YYYYMMDDhhmm
Example:
If it is run on 4/7/2010 5:23 then running
c:>\dt2file.cmd mystamp
an environmental variable with name mystamp is created with value 201007040523
No comments:
Post a Comment