Command Prompt/Bat file - Create new folder named with today's date

后端 未结 4 1055
误落风尘
误落风尘 2020-12-17 03:32

I use the following code to create a new folder that is named with todays date:

for /f \"tokens=1* delims=\" %%a in (\'date /T\') do set datestr=%%a
mkdir c:         


        
相关标签:
4条回答
  • 2020-12-17 04:02
    for /f "tokens=1-3 delims=/" %%a in ("%date%") do md "%%a_%%b_%%c"
    
    0 讨论(0)
  • 2020-12-17 04:20

    or simply

    SET Today=%Date:~10,4%_%Date:~7,2%_%Date:~4,2%
    
    echo %today%
    

    outputs

    2013_06_19
    Press any key to continue . . .
    

    Then you could easily use the variable today for directory creation e.g.:

    mkdir %today%
    

    EDIT: YYYY_MM_DD format

    0 讨论(0)
  • 2020-12-17 04:24

    %date% depends on your computer settings, and locale. Here is a reliable way to get a date and time stamp. Win XP pro and above.

    If you need to use your batch file on unknown machines then this is worth using.

    :: time and date stamp YYYYMMDD, HHMMSS and YYYY-MM-DD_HH-MM-SS
    @echo off
    for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
    set datestamp=%dt:~0,8%
    set timestamp=%dt:~8,6%
    set YYYY=%dt:~0,4%
    set MM=%dt:~4,2%
    set DD=%dt:~6,2%
    set HH=%dt:~8,2%
    set Min=%dt:~10,2%
    set Sec=%dt:~12,2%
    
    set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
    echo stamp: "%stamp%"
    echo datestamp: "%datestamp%"
    echo timestamp: "%timestamp%"
    
    pause
    
    0 讨论(0)
  • 2020-12-17 04:27

    Do this:

    for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set yyyymmdd1="%%k"_"%%i"_"%%j"
    mkdir %yyyymmdd1%
    
    0 讨论(0)
提交回复
热议问题