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

The Archive Base Latest Questions

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

Possible Duplicate: Creating date with numbers (new Date(2012, 03, …) gives wrong month (+1)

  • 0

Possible Duplicate:
Creating date with numbers (new Date(2012, 03, …) gives wrong month (+1)

I have this function:

function myFunction(){
 var d = new Date(2012,9,1);
var x = document.getElementById("demo");//some element demo

x.innerHTML=d.getDay();

}

I am trying to get the weekday on 1 date of any month . The code is above(an example).
Isn’t this supposed to return a saturday that is 6 as its value? It doesn’t give correct value. It gives 1 in this case.It seems simple but i am missing something.
am i misinterpreting the equation ?

Please tell.

some edit: Although it is a little bit different but still it was on the same line.

 function myFunction()
{

for(i=0;i<12;i++){

  var d = new Date(2012,i,0);

  k=i+1;

  var x = document.getElementById(""+k);

   x.innerHTML=d.getDate()+" "+i;


  }

}

This function writes the particular ids 12 total in no. and i get the following output:

31 0

31 1

29 2

31 3

30 4

31 5

30 6

31 7

31 8

30 9

31 10

30 11

That is not correct.

The function above is generating out months and corresponding days.

  • 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-10T16:05:36+00:00Added an answer on June 10, 2026 at 4:05 pm

    You forgot that when creating a new Date object, the month parameter takes a number between 0-11. September is 8. Try changing that to 8, and your day will return 6, which is Saturday.

    Your corrected code:

    function myFunction(){
    var d = new Date(2012,8,1);
    var x = document.getElementById("demo");//some element demo
    
    x.innerHTML=d.getDay();
    
    }
    

    Demo

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

Sidebar

Related Questions

Possible Duplicate: Creating an “object” of an interface I am new to Java. Based
Possible Duplicate: What is the 'new' keyword in JavaScript? creating objects from JS closure:
Possible Duplicate: Creating a custom Document Library in SharePoint I have 2 users, Martin
Possible Duplicate: Dynamically creating/inserting into an associative array in PHP I have the following
Possible Duplicate: Generate unique random numbers in Java I am creating a lottery app
Possible Duplicate: “new” keyword in Scala Ive noticed that creating certain instances in Scala
Possible Duplicate: Creating or assigning variables from a dictionary in Python Hello we have
Possible Duplicate: Creating a new Location object in javascript If the user inputs a
Possible Duplicate: C# - FileStream and creating folders I have an input directory where
Possible Duplicate: Creating jQuery AJAX requests to a PHP function How can i write

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.