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.

No comments:

Post a Comment

Featured post

SQL Server 2008 and SQL Server 2008 R2 - OUT of SUPPORT July 2019

Both SQL Server 2008 and SQL Server 2008 R2 go out of extended support with Microsoft in July 2019. That’s fast approaching and as we enter ...