Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:05:35+00:00 2026-06-10T20:05:35+00:00

I have written a rather small batch file that does some date calculations for

  • 0

I have written a rather small batch file that does some date calculations for me.

However, I have stumbled upon a minor problem:

Whenever I try to increment my month var, it simply sets the var to the desired incrementation. Code:

: How much time should we add? Default is 1 month
SET timeadd=1

: Set the date variables to build needed format
SET YYYY=%date:~-4%
SET MM=%date:~3,2%
SET DD=%date:~0,2%

if not %MM%==12 (
    SET /A MM=MM+timeadd
    SET changed=1
)

After the declaration, the month var would today (August 17th) be “08”.

After the if block however, this var would change to “1”.

I could guess that this is a conversion problem (date beeing a string, timeadd beeing an integer), however I really have no clue how to solve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:05:37+00:00Added an answer on June 10, 2026 at 8:05 pm

    As said in the comments, this is happening because a leading 0 indicates octal notation (just like a leading 0x indicates Hex notation), but the octal numbering system runs from 01 to 07, so there is no octal 08 or 09, rather it would be 010 and 011.

    Decimal Value 8 == Octal Value 010

    Decimal Value 9 == Octal Value 011

    To verify this for yourself, type this at the command-prompt

    c:\>set /a 010
    c:\>set /a 011
    

    Your output will be:

    8
    9
    

    =======================================

    My solution to this is simply to check for any leading 0‘s and delete them.

    if "%MM:~0,1%"=="0" set MM=%MM:~-1%
    

    Do any mathmatical magic I need done…

    set /a MM=%MM% + 1
    

    …and then add the leading 0‘s back on if necessary.

    set MM=0%MM%
    set MM=%MM:~-2%
    

    Just remember to make sure that it doesn’t exceed 12 (in this instance) or get lower than 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small app in C++ consisting of a single EXE file.
I have written a RNG class which holds different algorithms, however it does not
I have a small datasnap server written in Delphi 2007 that accesses the BDE.
I have a small utility app written in Visual Basic 6 that has been
I have written a packet reader that uses libpcap to read a capture file.
We have a rather large and complex application written in Java which is running
I have a rather large project whose Installer is written using NSIS. My problem
I have written a bash script which installs a number of packages, however for
I have written a function that sorts a big scale of data. To test
I have written a function that extract the domain from hostname. e.g. www.domain.com ->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.