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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:20:15+00:00 2026-05-25T11:20:15+00:00

I have a date object and I need to create another date object that

  • 0

I have a date object and I need to create another date object that is 1 week after the first date object. I already have an implementation but it seems that there is a bug with javascript when it reaches the months of October, November and December. Is there a workaround for this? Note that the behavior is consistent across Chrome, FF and IE.

        // ************ TEST#1 ************
        var startDate = new Date(2011,08,05); // set to Sept 5, 2011
        alert('START DATE' + startDate);

        var endDate = new Date();
        endDate.setDate(startDate.getDate() + 7);

        alert('END DATE' + endDate); // endDate is Sept 12 which is correct
        // check that startDate's value is unchanged
        alert('START DATE' + startDate); 


        // ************ TEST#2 ************
        var startDate = new Date(2011,10,05); // set to Nov 5, 2011
        alert('START DATE' + startDate);

        var endDate = new Date();
        endDate.setDate(startDate.getDate() + 7);

        alert('END DATE' + endDate); // endDate is Sept 12, 2011 which is wrong
        alert('START DATE' + startDate);



        // ************ TEST#3 ************
        // changed implementation but this won't work
        var startDate = new Date(2011,10,05);
        alert('START DATE' + startDate);

        var endDate = startDate;
        endDate.setDate(startDate.getDate() + 7);

        alert('END DATE' + endDate); // endDate is correct but...
        alert('START DATE' + startDate); // startDate's value has changed as well
  • 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-25T11:20:16+00:00Added an answer on May 25, 2026 at 11:20 am

    I think your error might be that you are setting endate to today.

        // ************ TEST#2 ************
        var startDate = new Date(2011,10,05); // set to Nov 5, 2011
        alert('START DATE' + startDate);
    
        // edit
        var endDate = new Date(startDate.getFullYear(),startDate.getMonth(),startDate.getDate() + 7);
        // old var endDate = new Date();
        // endDate.setDate(startDate.getDate() + 7);
    
        alert('END DATE' + endDate); // endDate is Sept 12, 2011 which is wrong
        alert('START DATE' + startDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a String representation of a date that I need to create a
On a JSTL/JSP page, I have a java.util.Date object from my application. I need
I need to create a java.util.Date object with an Australian timezone. this object is
So I have a Date object and I want to create a method so
I have a Date object ( java.sql.Date ). I need to get 12 at
I have been trying to add to the Watch window a Java Date object
Let's say I have an object: public class CustomObj { DateTime Date { get;
I have a bunch of objects that have a value and a date field:
I have an object containing a date and a count. public class Stat {
I have an application that is already using the Spring Framework and Spring JDBC

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.