in

This Blog

Syndication

Advertising

mystyleit

Pulling System Date and Time into Variables

It can be very useful to pull the date and time from the system and put it into variables. Once the date and time are in variables, they can be used to build filenames for log file, etc

First off, make sure the Regional Settings are set to the following:

The following script will pull the numerical date and time into variables.

REM ***************************************************************************
REM time variables

set month=%date:~4,2%
set day=%date:~7,2%
set year=%date:~10,4%

for /f "tokens=5-7 delims=:. " %%a in (
'echo/^|time^|find "current"'
) do set hour=%%a&set minute=%%b&set second=%%c

ECHO YEAR:%YEAR%
ECHO MONTH:%MONTH%
ECHO DAY:%DAY%

ECHO HOUR:%HOUR%
ECHO MINUTE:%MINUTE%
ECHO SECOND:%SECOND%

Now that you've got the date and time in variables, building a file name that contains the date and time is a snap.

SET logfile=%year%-%month%-%day% %hour%-%minute%-%second%.log
Published Oct 26 2007, 12:07 PM by mike.clarke
Filed under: , ,

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About mike.clarke

Mike is currently a Systems Specialist for a major Canadian software developer and the founder of mystyleit.com.