We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

noah on 10/21/09


Tagged

time date Shell script print windows variable log batch dos system bat win32


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

sulfurito


Print Date/Time in DOS Batch File


Published in: DOS Batch 


The code below shows how to format date and time stamps in DOS batch files. This is very useful if you are creating a log file, or any file that should have a unique file name.

If you run the batch file below it should print something like the following output:

Today's date is 2009_10_21

The local time is 14_25_01

Date and time: 2009_10_21_14_25_01
  1. set DATESTAMP=%DATE:~10,4%_%DATE:~4,2%_%DATE:~7,2%
  2.  
  3. set TIMESTAMP=%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2%
  4.  
  5. set DATEANDTIME=%DATESTAMP%_%TIMESTAMP%
  6.  
  7.  
  8.  
  9. echo Today's date is %DATESTAMP%
  10.  
  11. echo The local time is %TIMESTAMP%
  12.  
  13. echo Date and time: %DATEANDTIME%

Report this snippet 

You need to login to post a comment.