1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Resolved In bat file, need to parse date

Discussion in 'Windows XP' started by HARRYCAN, 2010/09/17.

  1. 2010/09/17
    HARRYCAN

    HARRYCAN Inactive Thread Starter

    Joined:
    2010/09/15
    Messages:
    3
    Likes Received:
    0
    In XP want to use bat file to get 2 digit year from %date% as variables for mm, dd, yy.
    Is there a way to trim the 4 digit year to 2 digits?
     
  2. 2010/09/17
    Steve R Jones

    Steve R Jones SuperGeek Staff

    Joined:
    2001/12/30
    Messages:
    12,315
    Likes Received:
    252
    Welcome to WindowsBBS;)

    Where are the dates stored?
    Are these files dates or dates stored in some application?
     

  3. to hide this advert.

  4. 2010/09/17
    HARRYCAN

    HARRYCAN Inactive Thread Starter

    Joined:
    2010/09/15
    Messages:
    3
    Likes Received:
    0
    I want to use something like the following:
    for /f "tokens=2-4 delims=/ " %%i in ('date/t') do (
    (set MM=%%i)
    (set DD=%%j)
    (set Yr=%%k)
    )
    The variable Yr is returned as 4 digits. I would like to reduce the year to 2 digits. I haven't tried basic commands ( right(%Yr%,2) )because I didn't think that would work in a bat file.
    Any ideas on how to trim the variable?
     
  5. 2010/09/17
    HARRYCAN

    HARRYCAN Inactive Thread Starter

    Joined:
    2010/09/15
    Messages:
    3
    Likes Received:
    0
    I was able to find the requested information.

    It is fairly simple, see below:

    SET MM=%date:~4,2%
    SET DD=%date:~7,2%
    SET YY=%date:~12,2%

    Thanks.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.