JSI Tip 7045. How do I use modulus to insure that day and month data can be converted to an arithmetic variable?
Jerold Schulman
August 10, 2003
1 Min Read
If you use a set command to convert a month or day string to an arithmetic variable, the command will fail when the string is 08 or 09. To see this behavior, open a CMD prompt and type:
set mm=08
set /a mm=%mm%
or
set mm=09
set /a mm=%mm%
You will receive:
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
To workaround this behavior, use the modulus operator:
set mm=08
set /a mm=100%mm%%%100
NOTE: See tip 6837 How do I convert the current month to an environment variable containing a 3 character month abbreviation?
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like