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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:43:57+00:00 2026-06-01T10:43:57+00:00

Hello i am trying to write the following function to display 7 days of

  • 0

Hello i am trying to write the following function to display 7 days of the week

function displaydates(){
// read the string output from the datepicker and
    //evalutes which date goes  into which cell

var date = document.getElementById("datepicker"); // Mon APR 30 2012 HH:MM:SS

var m = new Date(date.value);
var num = parseInt(m.getDate());
    var i = 0;
    var days=[];
    var x;
    for(i; i<=6; i++){
        var day= m.setDate(num+i);
        var month = m.setMonth(m.getMonth());
        x = m.getMonth()+1 + "/" + m.getDate() + "<br />";
        days.push(x);
    }
       document.getElementById("Monday").innerHTML= days[0];
       document.getElementById("Tuesday").innerHTML=days[1];
       document.getElementById("Wednesday").innerHTML=days[2];
       document.getElementById("Thursday").innerHTML=days[3];
       document.getElementById("Friday").innerHTML=days[4];
       document.getElementById("Saturday").innerHTML=days[5];
       document.getElementById("Sunday").innerHTML=days[6];
}

the code works fine as long as it’s seven days before the next month.the problem i am having is when the user wants to see the next seven day the function outputs the wrong information
for example

var m = new Date("Apr 30 2012"); / /monday

will make my function out put the following

4/29, 5/30, 7/1, 9/1, 11/2, 1/3, 3/7

again, this only happens on transition to the next month is there and thing i can do to make the month to month transition work in my function

  • 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-01T10:43:59+00:00Added an answer on June 1, 2026 at 10:43 am

    When you call, for example, setDate(32), JavaScript figures out that that requires an additional month and adds it to the date. When you later call setDate(33), it once again adds an extra month…

    This solution might work better (some parts are omitted):

    var start = new Date();
    var days = [];
    for(var i = 0; i <= 6; ++i) {
        var str = (start.getMonth() + 1) + '/' + start.getDate() + '<br />';
        days.push(str);
        start.setDate(start.getDate() + 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone I am trying to write a string on image during runtime and
hello everyone I'm trying to write function which can unfold int in the list
Hello I'm trying to write a CUDA kernel to perform the following piece of
I'm trying to write my own C++ String class for educational and need purposes.
Silly as it may sound, I am trying to write a simple function in
I am trying to extract links from HTML. I am using the following regular
I'm trying to write a perl script which takes the output of colorgcc (or
I'm trying to use Android Maps, following the instructions in Hello MapView . I've
I'm trying to write a regex function to remove onclick (also onload, onmouseover etc.)
I am trying to write a simple program that prints out a C string

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.