Windows命令行获取日期 [英] Windows Command line get date
问题描述
我要执行生成报告我为一个日期范围,我呼吁在命令行中的Program.exe一个Program.exe文件,但我必须设置两个参数(当前日期和< STRONG> CURRENT_DATE-6天),当我把它称为:
I have to execute a program.exe that generate me reports for a range of dates, I call the program.exe in a command line but i have to set two argument (current date and current_date-6days) when I call it :
C:\\ Program.exe文件CURRENT_DATE CURRENT_DATE-6(日期前6天)
我发现,这个命令让我当前日期:28-06-2013%日期:0,2〜% - %日期:〜-7,2% - %日期:〜-4,4%
i found that this command gives me the current date : 28-06-2013
%date:~0,2%-%date:~-7,2%-%date:~-4,4%
但我不能在 CURRENT_DATE -6(指日期前6天)
but I can't get the current_date-6 (means the date 6 days before)
我也让用户选择他想要的日期范围...
i have also to let the user choose the range of date he want ...
如何可以继续通过给他两个参数应用(当前日期,和之前对实施例6天数日期来执行程序1)自动地(视窗程序器))2)和手动的同时,通过给用户的选择一个日期范围的可能性
how I can proceed to execute the program 1 )automatically (windows schedular) by giving him the two parametres (current date , and date of 6 days before for example) 2) and manually in the same time, by giving the users the possibility of choosing a range of dates
@echo off
set /a currd=%date:~0,2%
set /a currm=%date:~3,2%
set /a curry=%date:~6,4%
set /a d=%date:~0,2%
set /a m=%date:~3,2%
set /a y=%date:~6,4%
FOR %%A IN (1 2 3 4 5 6) DO (
:loop
set /a d-=1
if %d% LSS 1 (
set d=1
set /a m-=1
if %m% LSS 1 (
set m=12
set /a y-=1
)
)
xcopy /d:%m%-%d%-%y% /l . .. >nul 2>&1 || goto loop
)
start /WAIT /B "" "C:\MyPGM.exe" "%d%-%m%-%y%" "%currd%-%currm%-%curry%"
对于28/06/2013我没有问题,但在2013年1月7日就产生了我一个错误
字符串未被识别为有效的DateTime
for the 28/06/2013 I have no problem but for the 01/07/2013 it generate me an error "String was not recognized as a valid DateTime"
推荐答案
本VBS脚本有给你最新的功能 - 6今天
This VBS script has the ability to give you date - 6 and today.
启动后才可以看到的帮助。
Launch it to see the help.
:: Date foward & backward
@echo off
if "%~2"=="" (
echo to get todays date use call "%~n0" today 0
echo to get yesterdays date use call "%~n0" today -1
echo to get 25 days before 19441213 call "%~n0" 1944/12/13 -25
echo to get 1250 days in the future call "%~n0" today 1250
echo.
echo Add a third parameter if you want a separator in the date string
echo EG: to use - as in YYYY-MM-DD for today's date
echo call "%~n0" today 0 -
echo.
pause
goto :EOF)
set date1=%1
set qty=%2
set separator=%~3
if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set day=%result:~0,4%%separator%%result:~4,2%%separator%%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)
pause
这篇关于Windows命令行获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!