JSI Tip 7045. How do I use modulus to insure that day and month data can be converted to an arithmetic variable?

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%


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?

Hide 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.