在批处理文件中获取前一个日期和前一个日期之前的日期(cmd)

问题描述:

我要确定日期并根据日期获取文件.我需要修改此抓取文件,该文件的日期为昨天和前天,即date-1和date-2.我需要更改什么?谢谢!

I have the following to determine the date and grab a file based on date. I need to modify this grab a file that has a date of yesterday and day before yesterday, i.e. date-1 and date-2. What do I need to change? Thanks!

echo @echo off > uploadsp.txt
set mydate=%date:~10,4%%date:~4,2%%date:~7,2%
echo set mydate=%date:~10,4%%date:~4,2%%date:~7,2% >> uploadsp.txt

set myfile=Epic_DSH360144_Drug_Utilization_%mydate%_DU.txt
echo put %myfile% >> uploadsp.txt
exit

您还可以非常轻松地调用powershell来获取日期并从中减去一天.

You can also call out to powershell very easily to grab the date and subtract a day from it.

For /F "delims=" %%G In ('PowerShell -Command "&{((Get-Date).AddDays(-1)).ToString('MMddyyyy')}"') Do Set "yesterday=%%G"