Batch: How to export yesterday's date keeping format [mm/dd/yyyy]?

前端 未结 2 897
遥遥无期
遥遥无期 2021-01-16 07:47

I am trying to create an environment variable for yesterday\'s date. It MUST be in the format of MM/DD/YYYY.

For code I currently have:



        
2条回答
  •  青春惊慌失措
    2021-01-16 08:22

    What you should do is use a method which is not based upon user/locale/PC settings. Commonly wmic is used for that, but it isn't the fastest method and would still require performing some math.

    You could use vbscript embedded directly into your batch-file:

    
    
    


    You could also, if you prefer it, use powershell from your batch-file instead:

    @Echo Off
    For /F %%# In ('PowerShell -NoP "(Get-Date).AddDays(-1).ToString('MM/dd/yyy')"'
    )Do Set "YesterDate=%%#"
    Echo(%YesterDate%
    Pause
    

提交回复
热议问题