DOS Batch Scripting is HELL


Okay. Figured I’d include this as well, because I don’t ever want to forget this part. Here’s how to set date and time variables in a DOS batch script.
 

for /f "tokens=1-7 delims=.:,/ " %%a in ("%date% %time%") do (
set day=%%c&set mon=%%b&set year=%%d&set hr=%%e&set min=%%f&set sec=%%g
)
echo %mon%
echo %day%
echo %year%
echo %hr%
echo %min%
echo %sec%

SET datex=%year%%mon%%day%
SET timex=%hr%%min%%sec%

echo %datex% %timex%

 
Obviously, we you don’t need all the echo statements, but it helps to define what’s what. This was tested on XP.

Advertisements

About mglaske

Systems Engineer for Limelight Networks
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s