MonthNumber
The MonthNumber function returns the number of a number from a month name.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:MonthNumber %month% mm
::
:: By: Ritchie Lawrence, 2003-05-14. Version 1.0
::
:: Func: Returns the number of month from name of month. Case insensitive
:: and only the first three letters are matched, result is 01 to
:: 12 or NULL if no match. For NT4/2000/XP/2003.
::
:: Args: %1 month name to convert to month number, Jan to Dec (by val)
:: %2 var to receive number of month (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set i=0
for %%a in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /a i+=1 & echo/%1|findstr /i /b "%%a" >nul && call set mm=%%i%%)
(if 1%mm% LSS 110 set mm=0%mm%) & endlocal&set %2=%mm%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Parameters
%1 month name to convert to month number, Jan to Dec (by val)
%2 var to receive number of month (by ref)
Return Values
Only the first three letters of the month are required. For example, if called with Apr or April, 4 is returned. This function is case insensitive. If the month name is invalid, NULL is required.
Example
@echo off & setlocal ENABLEEXTENSIONS
call :MonthNumber April mm
echo/April is month: %mm%
goto :EOF
Remarks
None.
The MonthNumber function returns the number of a number from a month name.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:MonthNumber %month% mm
::
:: By: Ritchie Lawrence, 2003-05-14. Version 1.0
::
:: Func: Returns the number of month from name of month. Case insensitive
:: and only the first three letters are matched, result is 01 to
:: 12 or NULL if no match. For NT4/2000/XP/2003.
::
:: Args: %1 month name to convert to month number, Jan to Dec (by val)
:: %2 var to receive number of month (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set i=0
for %%a in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /a i+=1 & echo/%1|findstr /i /b "%%a" >nul && call set mm=%%i%%)
(if 1%mm% LSS 110 set mm=0%mm%) & endlocal&set %2=%mm%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Parameters
%1 month name to convert to month number, Jan to Dec (by val)
%2 var to receive number of month (by ref)
Return Values
Only the first three letters of the month are required. For example, if called with Apr or April, 4 is returned. This function is case insensitive. If the month name is invalid, NULL is required.
Example
@echo off & setlocal ENABLEEXTENSIONS
call :MonthNumber April mm
echo/April is month: %mm%
goto :EOF
Remarks
None.
