Solved Batch File: Appending Date/Time to File Name?

September 27, 2012 at 12:49:08
Specs: Windows 7
I am attempting to append the date/time stamp to our outgoing files, but having a difficult time locating the correct variables to use in order to get the correct output.

* DOS Settings (Windows 2003 Server):

C:\Documents and Settings\camleh>date
The current date is: Thu 09/27/2012

C:\Documents and Settings\camleh>time
The current time is: 15:13:04.97

* Existing Script:

set d=%date:~-4,4%%date:~-7,2%%date:~0,2%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%

move "J:\CHR\OUT\*" "S:\Program Files\LexiCom\outbox\CHRobinson\ONECARE_%d%%t%.TXT"

Current Output: ONECARE_201227Th152636.TXT

Desired Output: ONECARE_20120927152636.TXT

Thanks in advance!

See More: Batch File: Appending Date/Time to File Name?

Report •

September 27, 2012 at 13:10:28
✔ Best Answer
I updated the below line and this appears to resolve it...

set d=%date:~4,2%%date:~7,2%%date:~10,4%

New Output: ONECARE_09272012160524.TXT

Report •
Related Solutions

Ask Question