Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Dec 2009
    Seattle, WA, USA
    Thanked 0 Times in 0 Posts

    Batch File behavior in windows 8

    In Windows 7, the following works:

    @echo off
    @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
    Set Month=%%A
    Set Day=%%B
    Set Year=%%C

    @echo off
    ::set date var
    Set D=%%C%%A%%B

    robocopy c:\users\bill f:\backup\%D%\

    I use this to set a directory name of the date I run the script for backups. ie: f:\backup\20150401

    However, in windows 8 and 8.1, it does not work. I don't have a Win 8 machine at the moment, so I can't troubleshoot. I tried to use this on a friends computer to provide an easy to retrieve backup process for him, but, the failure of the variable in the script ends up with f:\backup\username, not what I wanted to do.

    Any suggestions?



  2. #2
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    A cultural area in SW England
    Thanked 212 Times in 189 Posts
    I don't have a Windows 8 machine either, but just looking at the BATch file I suspect that
    DATE /T
    doesn't produce what it used to do in Windows 7 - in your locale.
    Microsoft occasionally does this, to show that standards aren't all they're cracked up to be!

    Furthermore, I think you need to use REM instead of :: for comments within FOR loops.

    I have used the following for constructing the useful year, month and day variables:
    @echo off
    :: obtain current DATE regardless of whether or not the operating system
    ::   gives the Day-of-the-Week as the first token from DATE /T
    ::   (works on NT4/W2K/WXP/W7/W10 to set variables %yy% (four digits), %mm% and %dd%)
    ::     by Ritchie Lawrence, modified by Garry Deane
    if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
    for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
      for /f "tokens=%toks% delims=.-/ "  %%e in ('date /t')     do (
        (set %%a=%%e) & (set %%b=%%f) & (set %%c=%%g)
    if 1%yy% LSS 200 set yy=20%yy%
    echo Date is: %dd%-%mm%-%yy%
    You can see that it's worked since before the Millennium!

    milliHelen (sub-unit): that quantity of female facial beauty sufficient to launch a single ship

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Thanked 1,117 Times in 1,040 Posts
    Here are a couple of responses from W8.1, exactly the same as W7 AFAICT.

    The current date is: 02/04/2015
    Enter the new date: (dd-mm-yy)

    C:\Users\Paul>date /t

    The batch file works if you use this: tokens=1,2,3
    It should be the same in Windows 7 unless you have a white space at the beginning of the date response - I get one at the end, after year.

    cheers, Paul

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts