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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:24:43+00:00 2026-06-13T17:24:43+00:00

Why do these two dates are differents : var date1 = new Date(); date1.setFullYear(2012);

  • 0

Why do these two dates are differents :

var date1 = new Date();
date1.setFullYear(2012); // year (four digits)
date1.setMonth(10); // month (from 0-11)
date1.setDate(1); // day of the month (from 1-31)

var date2 = new Date(2012, 10, 1, 0, 0, 0, 0);

Result :

Date 1 : Sat Dec 01 2012 14:56:16 GMT+0100
Date 2 : Thu Nov 01 2012 00:00:00 GMT+0100

whereas these two dates are equals :

var date3 = new Date();
date3.setFullYear(2012); // year (four digits)
date3.setMonth(9); // month (from 0-11)
date3.setDate(1); // day of the month (from 1-31)

var date4 = new Date(2012, 9, 1, 0, 0, 0, 0);

Result :

Date 3 : Mon Oct 01 2012 14:56:16 GMT+0200
Date 4 : Mon Oct 01 2012 00:00:00 GMT+0200

Another question is why do date1.setMonth(10) gives a date in December (should be November).

  • 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-13T17:24:44+00:00Added an answer on June 13, 2026 at 5:24 pm

    Finally got it. new Date() sets the date to the current date and time. In other words, October 31st (at the time of this writing).

    When you then try to set the month to November, what’s it to do? November only has 30 days… so it wraps it round to December.

    If you change the order so that you set the day-of-month before the month, it works:

    var date1 = new Date();
    date1.setFullYear(2012); // year (four digits)
    date1.setDate(1); // day of the month (from 1-31)
    date1.setMonth(10); // month (from 0-11)
    

    Or as implied by jbabey’s answer:

    var date1 = new Date();
    date1.setFullYear(2012); // year (four digits)
    date1.setMonth(10, 1); // month (from 0-11) and day (1-31)
    

    The documentation isn’t terribly clear, but it’s at least suggestive:

    If a parameter you specify is outside of the expected range, setMonth attempts to update the date information in the Date object accordingly. For example, if you use 15 for monthValue, the year will be incremented by 1 (year + 1), and 3 will be used for month.

    (“Accordingly” is far from precise, but it means the implementation is at least arguably correct…)

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

Sidebar

Related Questions

I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have a two dates $date1=03/17/2012 9:00 PM; $date2=03/17/2012 9:40 PM; I have to
Of these two options: var result = from c in coll where c %
I'm trying to determine the number of leap year days between two different dates
These two methods appear to behave the same to me public IEnumerable<string> GetNothing() {
These two files are mostly seen in open source projects. What are they for,
These two querys gives me the exact same result: select * from topics where
These two queries work: SELECT u.id, u.email, COUNT(*) as Current FROM users u, rounds
So these two methods have the same signature but different constraints public static void
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2

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.