Sunday, January 18, 2009

How to Create Time Stamp appended to a File name in a Batch File in DOS

This is how I came up with creating Batch files in DOS for manipulating Date and time. Here I am creating a time stamp and store it in Variable "T", which I append after the Output File FSA_ERROR_RESULT.

set timest=%time:~0,8%
set timest1=%time:~0,8%
if @%timest:~0,1% == @ set timest=0^%timest:~1,7%
set T=%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%^_^%timest:~0,2%^%timest:~3,2%^%timest:~6,2%
move D:\archive\FSA_ERROR_RESULT.csv C:\FSA_ERROR_RESULT_%T%.csv
if %timest1:~0,1%==1 @set T=%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%^_^%timest1:~0,2%^%timest1:~3,2%^%timest1:~6,2%
move D:\archive\FSA_ERROR_RESULT.csv C:\FSA_ERROR_RESULT_%T%.csv

As, you would note, this code takes care of the bug that comes up before 10 am. Guys, feel free to use this code as and when you need.

Regards,
Shweta Purohit Chaturvedi