date in filename in batch file - Windows NT

This is a discussion on date in filename in batch file - Windows NT ; Hi, I've come across a batch file that uses syntax such as this when copying to a newly named file: %DATE:~4,2% By testing, I've found that %date% results in the date (e.g. Thu 03/03/2005), and that the :~4,2 syntax basically ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: date in filename in batch file

  1. date in filename in batch file

    Hi,
    I've come across a batch file that uses syntax such as this when
    copying to a newly named file:

    %DATE:~4,2%

    By testing, I've found that %date% results in the date (e.g. Thu
    03/03/2005), and that the :~4,2 syntax basically takes a substring from
    the result. For example, echo %path:~4,5% results in 5 characters of
    the path variable, starting with the 4th character (if you start
    counting at zero).

    It's useful, but try as I might, I can't find it documented anywhere.
    Does anyone know where this might be documented?
    I know this works in Windows 2000 and XP.
    Thanks,
    Scott


  2. Re: date in filename in batch file


    "scottgp" wrote in message
    news:1109873111.803975.49960@f14g2000cwb.googlegro ups.com...
    > Hi,
    > I've come across a batch file that uses syntax such as this when
    > copying to a newly named file:
    >
    > %DATE:~4,2%
    >
    > By testing, I've found that %date% results in the date (e.g. Thu
    > 03/03/2005), and that the :~4,2 syntax basically takes a substring from
    > the result. For example, echo %path:~4,5% results in 5 characters of
    > the path variable, starting with the 4th character (if you start
    > counting at zero).
    >
    > It's useful, but try as I might, I can't find it documented anywhere.
    > Does anyone know where this might be documented?
    > I know this works in Windows 2000 and XP.
    > Thanks,
    > Scott
    >


    Type set /? at the Command Prompt.



  3. Re: date in filename in batch file

    Ah. Thanks so much, that was driving me nuts. ":~" is not something
    you can search on, either.
    Scott


+ Reply to Thread