Setting a windows batch file variable to the day of the week

后端 未结 17 2014
南方客
南方客 2020-11-27 20:14

I have a windows batch file that runs daily. Wish to log data into a file and want to rotate it (i.e. having at most the last 7 days worth of data).

Looked into the

17条回答
  •  广开言路
    2020-11-27 21:01

    I am in the US. I can run this code in Windows 7, Windows 2008 R2, Windows Server 2003, Windows XP (All OS's are current with Windows Updates and patches). All with short date setting without ffffd (or ffffdd) (day of week).

    @echo off
    for /f %%a in ('date /t') do set DAY=%%a
    echo.
    echo The Day Is: %DAY%
    echo.
    

    If today is Thursday, it would output "The Day Is: Thu".

    This returns the day on all 4 Windows versions I have tested on. And only the day. When I changed my short date setup to be "ffffd, M/d/yyyy", my output would show the day with a comma (e.g. Thu,) which tells me this code does use the short date format. But what also may be happening is that if the short date does not contain the day of week, it may look to the long date format which on all 4 machines I tested on, have ffffdd in the format.

提交回复
热议问题