4 Answers
4

In the command prompt and batch files, you can use %date% and %time% to return the date and time respectively. Date works fine, but the time value returned contains colons, which are illegal for use in filenames, but there is a way to remove those.

Great little tip. BTW, if you do it the other way around, that is: "file_20090601_172215", you will see the files in the correct order in an alphabetic list.
– TonJJun 1 '09 at 13:00

5

You can also use %time::=% to remove the colons.
– grawityJun 1 '09 at 13:33

2

I'd say that date substring-ing would break as soon as the system locale differs from when the script was tested? It could even work for the testing user and break as the script runner because of different date display formats set...
– Oskar DuvebornJun 1 '09 at 18:17

3

Beware hours 0 - 9! CMD sets the first character of the hour to <SPACE>, rather than 0. The COPY command above is going to have problems if you don't enclose the destination filename in quotes.
– Evan AndersonJun 1 '09 at 20:09

2

Note that %DATE% and %TIME% are locale-aware! It means that on a European machine, you get DD.MM.YYYY. Arrgh.
– Pekka 웃Jan 26 '11 at 20:36

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).