1.

Solve : Capture the systems year, month, date, hours, mins, and second.?

Answer»

I would like to capture the systems year, month, date, hours, mins, and second as a parameter. As a NAME to rename one of my file. How can i do it .

@set a=%date:~0,2%-%date:~3,2%-%date:~6,8%-%TIME:~1,1%-%time:~3,2%-%time:~6,2%-%time:~9,3%


you can use vbscript to get the date/time, independent of your COMP's regional settings
then use the batch for loop, set tokens, can capture the output
Code: [Select]WScript.Echo DatePart("yyyy" , Now),DatePart("d" , Now),DatePart("m" , Now),DatePart("h", Now),DatePart("n" , Now),DatePart("s" , Now)

Quote from: Diablo416 on August 17, 2007, 05:46:40 AM



@set a=%date:~0,2%-%date:~3,2%-%date:~6,8%-%time:~1,1%-%time:~3,2%-%time:~6,2%-%time:~9,3%




Would you mind EXPLAIN the logic to me.

sure,

today is 17/08/2007 according to %date%
if you typed echo %date:~0,2% it would echo only 17
echo %date:~0,3% would echo 17/ , if you typed echo %date:~2,3%
it would echo /08,expand the variable after the letter with :~ the numbers 0,0
are line positions

@set a=%date:~0,2%-%date:~3,2%-%date:~6,8%-%time:~1,1%-%time:~3,2%-%time:~6,2%-%time:~9,3% &LT;< here i used postions that wont show a \ ,so that when you use %A% as a file name. because \ might not allow it, i replaced them with dashes -


Discussion

No Comment Found