Wednesday, 20 July 2011

DOS Batch File Date and Time

Written by David POstlethwaite

A non SQL blog for a change
 
Ever needed to create a batch file that wrote a time stamped log file that ensures the day and month number always have two digits?
 
Try this:
 
SET Now=%Time: =0%
Set YYYYMMDD=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%_%now:~0,2%%now:~3,2%
 
echo running Batch File.... >> %YYYYMMDD%.txt

I hope you found this helpful, please feel free to leave a comment.