VBScript date calculation

  • Thread starter Thread starter hon
  • Start date Start date
H

hon

Hi all,
I would like to creat a vbs which can download file which format
file_20060901.zip (fileYYYYmmdd.zip)
and create a folder which is 2 calendar days before which is DIR_20060830.
How can I get the date and do calculation? Thanks!

Rgd,
Ben
 
Hi all,
I would like to creat a vbs which can download file which format
file_20060901.zip (fileYYYYmmdd.zip)
and create a folder which is 2 calendar days before which is DIR_20060830.
How can I get the date and do calculation? Thanks!

Rgd,
Ben


@echo off
:: from code by Phil Robyn
setlocal
if [%1]==[] (
echo to get todays date use
echo call "%~n0" today 0
echo.
echo to get yesterdays date use
echo call "%~n0" today -1
echo.
echo to get the date 25 days ago:
echo call "%~n0" today -25
echo.
echo to get the date 1250 days in the future
echo call "%~n0" today +1250
goto :EOF)

set date1=%1
set qty=%2
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%-%result:~4,2%-%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)
 
Back
Top