I developed this script to use when naming files that needed to be uniqueand also to reference a date and time in the file name. This script will create a variable that will contain the date and time in the following format:

MM-DD-YYYY-HHh-MMm-SS.SSsor 09-28-2007-12h38m55.72s

The main line in the script is a single command line command:

if %time:~0,1%A==A (echo %date:~4,2%-%date:~7,2%-%date:~10,4%-0%time:~1,1%h%time:~3,2%m%time:~6,5%s>>#AgentTemp##DTSLogFile#) else (echo %date:~4,2%-%date:~7,2%-%date:~10,4%-%time:~0,2%h%time:~3,2%m%time:~6,5%s>>#AgentTemp##DTSLogFile#)

The %time% variable outputs time in a 24 hour format, but does not pad single digit hours with a zero, so we fix that. First, we check to see if the%time% variable has any numbers starting from position 0 for 1 position. If there is not a number in this position (it returns the letter A only, meaning the time is between 1:00 am and 9:59 am), then we padthe time portion of the redirected output with a zero (01:00 and 09:59) and only read in the hour portion of the %time% variable starting at position 1 for 1 position (0%time:~1,1%). Else, justread in both positions ofthe %time% variable (%time:~0,2%h).

You could use this script and its resulting variable #DTStamp#for naming backup files or any other file where you need aunique file name.

Legacy Forum Name: Script to generate a date and time stamp for naming files,
Legacy Posted By Username: gssloan