Monday, November 22, 2010

Set current date and time variable in Batch file

Check your system date format at first:
The current date is: 11/23/2010 Tue
so the format is mm/dd/yyyy weekday

It might be different from other computer, some of are put weekday in the front of the date:
The current date is: Tue 11/23/2010

Here we take 11/23/2010 Tue as an example:
@echo off  
SET inputdate=%date:~6,4%%date:~0,2%%date:~3,2%  
SET inputtime=%time:~0,2%%time:~3,2%%time:~6,2%  
echo %inputdate%_%inputtime%_Rawdata.jtl

 Output:20101122_234425_Rawdata.jtl  

PS: no space between ‘=’ and ‘%’, it costs me 10 mins around this...

No comments:

Post a Comment