This trick is useful for both troubleshooting batch file tasks and when using a batch file to create a log. For example I have a scheduled task that renames some of my backup folders at night and then moved a few files around for me. When the batch file starts I uses the below code to print the time it starts, I repeat the two lines at the end of the batch file so that I can see what time the job completed. This is useful for figuring out average time of a task so that you can schedule other things without interfering.
Date /T >> c:\script.log
Time /T >> c:\script.log
Time /T >> c:\script.log
Â
And here is what it looks like in a actual batch file:
Echo running backup script >> G:\log\backup.log
Date /T >> G:\log\backup.log
Time /T >> G:\log\backup.log
Rename f:\backup\full f:\backup\full_old
md f:\backup\full
Move f:\backup\full_old g:\archive
Delete f:\backup\full\log.txt
Echo completed at >> G:\log\backup.log
Date /T >> G:\log\backup.log
Date /T >> G:\log\backup.log
Time /T >> G:\log\backup.log
Rename f:\backup\full f:\backup\full_old
md f:\backup\full
Move f:\backup\full_old g:\archive
Delete f:\backup\full\log.txt
Echo completed at >> G:\log\backup.log
Date /T >> G:\log\backup.log
Time /T >> G:\log\backup.log
Â
The output would look like:
Running backup script
Thu 04/23/2009
10:53 AM
Completed at
Thu 04/23/2009
11:23 AM
Thu 04/23/2009
10:53 AM
Completed at
Thu 04/23/2009
11:23 AM