How do I get the day month and year from a Windows cmd.exe script?

前端 未结 14 1356
长情又很酷
长情又很酷 2020-12-23 17:02

How do I get the current day month and year from inside a Windows cmd script? I need to get each value into a separate variable.

相关标签:
14条回答
  • 2020-12-23 17:26

    You can use simple variable syntax, here is an example:

    @echo off
    set month=%date:~0,2%
    set day=%date:~3,2%
    set year=%date:~6,4%
    echo The current month is %month%
    echo The current day is %day%
    echo The current year is %year%
    pause >nul
    

    Another option is the for command, again here is my example:

    @echo off
    for /f "delims=/ tokens=1-3" %%a in ("%date%") do (
    set month=%%a
    set day=%%b
    set year=%%c
    )
    echo The current month is %month%
    echo The current day is %day%
    echo The current year is %year%
    pause >nul
    
    0 讨论(0)
  • 2020-12-23 17:26
    powershell Set-Date -Da (Get-Date -Y 1980 -Mon 11 -Day 17)
    
    0 讨论(0)
提交回复
热议问题