Showing posts with label cmd. Show all posts
Showing posts with label cmd. Show all posts

Monday, March 21, 2016

DateTime Stamp in Windows cmd and dos

This will will create a datetime stamp for a log file in Windows.
 
 
1. Create a cmd or bat file and copy the below text into the file and save.
 

 
@------------------ 
 
@Echo Off

for /f "tokens=1-5 delims=:" %%d in ("%time%") do set var=%date:~10,4%%date:~4,2%%date:~7,2%-%%d%%e

set datetimestr=%var: =0%

set logfile=LogFile-%datetimestr%.txt

echo %logfile%
 
 
 
Thanks to this post this worked for me. 
 
Ref: http://superuser.com/questions/315984/how-to-get-the-date-in-a-batch-file-in-a-predictable-format/316153