我有查询以格式25012014获取sysdate。查询是
@echo off
SetLocal enabledelayedexpansion
for /f "tokens=2-4 delims=/ " %%a in ('') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY1=%day%%month%%year%
echo %TODAY%
如何获取前几天的日期?
答案 0 :(得分:1)
:: yesterdays date
@echo off
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "date-yesterday=%mm%%dd%%yyyy%"
echo Yesterday was "%date-yesterday%"
pause
答案 1 :(得分:1)
@ECHO OFF
SETLOCAL
FOR %%d IN (01 15) DO FOR %%m IN (01 03 05 12) DO FOR /l %%y IN (2010,1,2014) DO (
SET day=%%d&SET month=%%m&SET year=%%y
CALL :proc
)
GOTO :EOF
:proc
SET today=%day%%month%%year%
SET /a yesterday=%year% %% 4
SET /a day=1%day%-1
IF %day:~-2%==00 SET /a month=1%month%-1&SET day=131&FOR %%L IN (03 03 05 07 10 12) DO IF %%L==%month% SET /a day-=1
IF %month:~-2%==00 (SET /a month=112&SET /a year-=1) ELSE (IF %yesterday% neq 0 if %month:~-2%==02 set/a day-=1)
SET yesterday=%day:~-2%%month:~-2%%year%
ECHO The day before %today% was %yesterday%
GOTO :eof
例程:proc
实际上进行了转换,三重嵌套for
循环只是为了获取重要的测试日期。
为我工作!