Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 批量获取两个日期之间的天数_Date_Batch File - Fatal编程技术网

Date 批量获取两个日期之间的天数

Date 批量获取两个日期之间的天数,date,batch-file,Date,Batch File,我正在做一个自动更新系统,如果软件在一定时间内没有更新,我需要系统打开一个网页。我会记录每次自动更新的日期,因此我需要的帮助是获取上次自动更新和当前日期之间的天数。我希望您也能解释一下您的代码,非常感谢您的努力,提前谢谢。您也可以尝试类似的方法 set/p searchdate= Enter search date (ddmmyyyy): 我把这个藏起来了: :: Using Powershell :: Count the number of days from %1 to %2

我正在做一个自动更新系统,如果软件在一定时间内没有更新,我需要系统打开一个网页。我会记录每次自动更新的日期,因此我需要的帮助是获取上次自动更新和当前日期之间的天数。我希望您也能解释一下您的代码,非常感谢您的努力,提前谢谢。

您也可以尝试类似的方法

    set/p searchdate= Enter search date (ddmmyyyy):  

我把这个藏起来了:

:: Using Powershell
:: Count the number of days from %1 to %2 
:: date format is yyyy/mm/dd

@echo off
set from=2001/01/01
set to=2011/12/19
if not "%~1"=="" set from=%1
if not "%~2"=="" set to=%2
set /a a1=%from:~0,4% + 1
set /a a2=%to:~0,4% - 1
if %from:~0,4% EQU %to:~0,4% (
set "sameyear=(get-date %to%).dayofyear - "
) else (
set "sameyear=(get-date %from:~0,4%/12/31).dayofyear - " 
)

>file.ps1  echo Set-ExecutionPolicy unrestricted
>>file.ps1 echo $a=%sameyear%(get-date %from%).dayofyear

for /L %%a in (%a1%, 1, %a2%) do (
>>file.ps1 echo $a=$a + (get-date %%a/12/31^).dayofyear
)

if NOT %from:~0,4% EQU %to:~0,4% (
>>file.ps1 echo $a=$a + (get-date %to%^).dayofyear
)
>>file.ps1 echo.echo $a

for /f "delims=" %%a in (
'powershell -file file.ps1'
) do set total=%%a
del file.ps1 2>nul
echo The Total number of days from %from% until %to% is %total%

这里有一个使用VBS的解决方案

@echo off
set "from=01-01-2001"
set "to=12-19-2011"
echo Wscript.Echo #%to%# - #%from%# >tmp.vbs
for /f %%a in ('cscript /nologo tmp.vbs') do set "total=%%a"
del tmp.vbs
echo The Total number of days from %from% until %to% is %total%

你能提供一些代码吗?到目前为止你都尝试了什么?没有,我不知道任何codeStackOverflow都不是一个让人们代替你编码的地方。您必须向我们展示您所做的工作(当前代码、结构、类等),这样我们才能帮助您。看起来很简单,我会试试