bat脚本计算前一天的日期
时间: 2023-04-05 19:01:07 浏览: 68
你好,我可以回答这个问题。可以使用以下代码计算前一天的日期:
```
@echo off
setlocal enabledelayedexpansion
set "today=!date!"
set /a "day=1%today:~0,2%-100, month=1%today:~3,2%-100, year=today:~6,4%"
set /a "day-=1"
if !day! == 0 (
set /a "month-=1"
if !month! == 0 (
set /a "year-=1"
set "month=12"
)
set /a "day=31"
if !month! == 4 (
set /a "leap=year%%4"
if !leap! == 0 set /a "day=30"
)
if !month! == 6 (
set /a "day=30"
)
if !month! == 9 (
set /a "day=30"
)
if !month! == 11 (
set /a "day=30"
)
if !month! == 2 (
set /a "leap=year%%4"
if !leap! == 0 set /a "day=29"
if !leap! neq 0 set /a "day=28"
)
)
set "month=0!month!"
set "day=0!day!"
set "year=!year:~-4!"
set "yesterday=!year!!month:~-2!!day:~-2!"
echo Yesterday's date is %yesterday%.
```
希望能帮到你。
阅读全文