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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:07:42+00:00 2026-05-30T20:07:42+00:00

(first, sorry for my bad english, i’m a beginner) I have a chart of

  • 0

(first, sorry for my bad english, i’m a beginner)

I have a chart of percent by date. I would like to display every day of the current week in the x-axis.

So, i tried to find how to get the seven days of the week.
that’s what i have :

var curr = new Date; // get current date
var first = curr.getDate() - curr.getDay();//to set first day on monday, not on sunday, first+1 :

var firstday = (new Date(curr.setDate(first+1))).toString();

for(var i = 1;i<7;i++){
var next = first + i;
var nextday = (new Date(curr.setDate(next))).toString();
alert(nextday);
}

the alert begins well…until the end of the month. That’s what i got :

1 : "Mon 27 Feb 2012 ..."
2 : "Tue 28 Feb 2012 ..."
3 : "Wed 29 Feb 2012 ..."
4 : "Thu 01 Mar 2012 ..."
5 : "Sat 31 Mar 2012 ..."
6 : "Sun 01 Apr 2012 ..."

So, as you can see, it switches the friday and… strangely it switch to the good date…4 weeks later…

So, do you have a better solution for me, or maybe you could just help me and say what is the problem.

Thank you!

  • 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-05-30T20:07:44+00:00Added an answer on May 30, 2026 at 8:07 pm

    I’m afraid you have fallen into one of the numerous traps of object mutation. 🙂

    The problem is that, in the line “var nextday = …”, you are changing the date saved in “curr” on every iteration by calling setDate(). That is no problem as long as next is within the range of the current month; curr.setDate(next) is equivalent to going forward one in this case.

    The problems begin when next reaches 30. There is no February 30, so setDate() wraps around to the next month, yielding the 1st of March – so far so good. Unfortunately, the next iteration calls curr.setDate(31), and as curr is the 1st of March (remember that the object referenced by curr is changed in each iteration), we get… March 31! The other strange values can be explained the same way.

    A way to fix this is to copy curr on each iteration and then call setDate(), like so:

    for (var i = 1; i < 7; i++) {
        var next = new Date(curr.getTime());
        next.setDate(first + i);
        alert(next.toString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, sorry for my bad english. I would like when one people click on
First, sorry for my bad english. I have an EF entity that looks like:
First, sorry for my bad english, I'm French. Here the problem : I have
First, sorry for bad english :-) On a little website i own, i would
first,sorry for my bad English!! i'm new here and i'm a beginner of android
First of all, sorry for my bad English... I have a problem with one
First of all, I'm sorry for my bad English. I have a Windows Server
first, sorry for the bad english. I have a test that submit a login
First sorry for my bad English. I have this menubar in PHP. I want
First thanks for reading me and sorry for my bad english. I have the

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.