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

  • SEARCH
  • Home
  • 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 9232535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:20:15+00:00 2026-06-18T06:20:15+00:00

A Date object’s getMonth() method seems to have a bug. Assuming the Date d

  • 0

A Date object’s getMonth() method seems to have a bug. Assuming the Date d is 2013-01-31, I attempt to set the month on d like this:

const d = new Date(); // 2013-01-31

d.setMonth(8);
console.log(d.getMonth());

The result is 9. Why? I tested this both in Chrome and Firefox.

I found out that when it’s the 31st, 30th, or 29th of a month, setting the date to a month that has a fewer number of days causes getMonth to return the wrong value.

  • 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-18T06:20:16+00:00Added an answer on June 18, 2026 at 6:20 am

    Let’s break this down:

    var d = new Date(); // date is now 2013-01-31
    d.setMonth(1);      // date is now 2013-02-31, which is 3 days past 2013-02-28
    x = d.getMonth();   // what to do, what to do, 3 days past 2013-02-28 is in March
                        // so, expect x to be March, which is 2
    

    This is only an issue when the day value of d is greater than the maximum number of days in the month passed to setMonth(). Otherwise, it works as you’d expect.

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

Sidebar

Related Questions

I cant get the month and day from the date object like this :
I have about eight prototype functions for the Date object. I would like to
I'm creating random time in random date in next month like this var time
So I have a Date object and I want to create a method so
I have a date object: var thedate = new Date(2012-05-02T11:00:00.000+0000); When I do getMonth()
I have an annoying bug in on a webpage: date.GetMonth() is not a function
I have a Java date object: Date currentDate = new Date(); This will give
I have a Javascript Date object equal to 00:30 and when doing: date.setMinutes(date.getMinutes() +
I have a current Date object that needs to be incremented by one day
I need to obtain a Date object from this String:This is a example) M-27\nJUN-2012

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.