Q. How can a script return the number of days in the current month?

I have scripted DaysThisMonth.bat to return the number of days in the current month.

The syntax for using DaysThisMonth.bat is:

\[call\] DaysThisMonth Days

Where Days is a call directed numeric environment variable that will contain the number of days in the current month.

DaysThisMonth.bat contains:

@echo off
if \{%1\}==\{\} @echo DaysThisMonth Days&goto :EOF
if exist "%TEMP%\DaysThisMonth.vbs" goto doit
@echo.dt = Date()>"%TEMP%\DaysThisMonth.vbs"
@echo.ld = Day(DateSerial(Year(dt), 1 + Month(dt), 0))>>"%TEMP%\DaysThisMonth.vbs"
@echo.wScript.Echo ld>>"%TEMP%\DaysThisMonth.vbs"
:doit
set /a %1=0
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\DaysThisMonth.vbs"') do (
 set /a %1=%%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