Q. How can a script return the number of days in the month for a specified date?

I have scripted DaysMonth.bat to return the number of days in the month for a specified date.

The syntax for using DaysMonth.bat is:

\[call\] DaysMonth Date Days

Where:

Date contains a valid date.

Days is a call directed numeric environment variable that will contain the
 number of days in the month for Date.
DaysMonth.bat contains:
@echo off
if \{%2\}==\{\} @echo DaysMonth Date Days&goto :EOF
if exist "%TEMP%\DaysMonth.vbs" goto doit
@echo.Dim Arguments>"%TEMP%\DaysMonth.vbs"
@echo.Set Arguments = Wscript.Arguments>>"%TEMP%\DaysMonth.vbs"
@echo.yyyy = DatePart("yyyy", Arguments(0))>>"%TEMP%\DaysMonth.vbs"
@echo.mm = Right(100+DatePart("m", Arguments(0)),2)>>"%TEMP%\DaysMonth.vbs"
@echo.ld = Day(DateSerial(yyyy, 1 + mm, 0))>>"%TEMP%\DaysMonth.vbs"
@echo.wScript.Echo ld>>"%TEMP%\DaysMonth.vbs"
:doit
set /a %2=0
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\DaysMonth.vbs" %1') do (
 set /a %2=%%a
)


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish