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 8464305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:42:21+00:00 2026-06-10T14:42:21+00:00

While trying to find out why I was having issues while working on a

  • 0

While trying to find out why I was having issues while working on a calendar, I ran into this issue. When setting the month to 8, the date is set to October, when the month is set to 9, the date is set to October.
Code to test

var d = new Date();
document.write(d.getMonth());
d.setMonth(8);
document.write(d.getMonth());
d.setMonth(9);
document.write(d.getMonth());

output:
799

The current date is August 31st 2012, the month number should be 7, since the javascript months are 0 based.

Can someone explain this? I have been able to reproduce it on more than one computer.

  • 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-10T14:42:23+00:00Added an answer on June 10, 2026 at 2:42 pm

    September only has 30 days – when you set the day to 31 (or create a date on the 31st of some month) and then change the month to one with fewer than 31 days JavaScript rolls the date over into the next month (in this case October). In other words, the date overflows.

    > var d = new Date()
    > d
    Fri Aug 31 2012 22:53:50 GMT-0400 (EDT)
    // Set the month to September, leaving the day set to the 31st
    > d.setMonth(8) 
    > d
    Mon Oct 01 2012 22:53:50 GMT-0400 (EDT)
    
    // Doing the same thing, changing the day first
    > var d = new Date()
    > d
    Fri Aug 31 2012 22:53:50 GMT-0400 (EDT)
    > d.setDate(30)
    > d
    Thu Aug 30 2012 22:53:50 GMT-0400 (EDT)
    > d.setMonth(8)
    Sun Sep 30 2012 22:53:50 GMT-0400 (EDT)
    

    So the simple answer is, because the date for today is the 31st of August and the 31st of September is October 1st.

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

Sidebar

Related Questions

While trying to find an answer to Android Jasper Reporting I found out that
Been trying to find this online for a while now. I have a SDL_Surface
I have been trying to find some resource on this topic for a while
i feel my beard growing while trying to find out the Problem here. Basic
I'm having trouble describing this issue, which is probably why I can't find the
I've been having an extremely difficult time trying to find an answer for this.
I've been trying to work this our for a while, but having trouble. We
I've been researching for a while now trying to find a reason why the
While trying to use XMLWorkerHelper.GetInstance().ParseXHTML() i find that it is really strict. Any wrong
While trying to profile my Perl program, I find that Math::Complex is taking up

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.