Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Capture the systems year, month, date, hours, mins, and second.  (Read 4317 times)

0 Members and 1 Guest are viewing this topic.

cityjack

  • Guest
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 .

diablo416

  • Guest
Re: Capture the systems year, month, date, hours, mins, and second.
« Reply #1 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%



ghostdog74



    Specialist

    Thanked: 27
    Re: Capture the systems year, month, date, hours, mins, and second.
    « Reply #2 on: August 17, 2007, 09:40:20 AM »
    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)


    cityjack

    • Guest
    Re: Capture the systems year, month, date, hours, mins, and second.
    « Reply #3 on: August 17, 2007, 11:16:57 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.

    diablo416

    • Guest
    Re: Capture the systems year, month, date, hours, mins, and second.
    « Reply #4 on: August 17, 2007, 11:57:02 AM »


    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% << 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 -