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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:54:03+00:00 2026-05-22T22:54:03+00:00

I’m working with javascript Date objects and seeing very odd behavior. If I keep

  • 0

I’m working with javascript Date objects and seeing very odd behavior. If I keep setting a date object to another date object + an offset, it starts adding 30 days or so. If I reset the date object in between attempts or if I do the date math on the same object it works as expected.

Probably easier to see the test bed I’m running in the latest chrome/ff:

var date = new Date();
console.log("start:", date);

var test = new Date();
test.setDate( date.getDate() + 1 );
console.log("test1:", date, test);
test.setDate( date.getDate() + 1 );
console.log("test2:", date, test);
test.setDate( date.getDate() + 1 );
console.log("test3:", date, test);

test = new Date();
test.setDate( date.getDate() + 1 );
console.log("test reset 1:", date, test);
test = new Date();
test.setDate( date.getDate() + 1 );
console.log("test reset 2:", date, test);
test = new Date();
test.setDate( date.getDate() + 2 );
console.log("test reset 3:", date, test);

test = new Date();
test.setDate( test.getDate() + 1 );
console.log("test selfref 1:", test);
test.setDate( test.getDate() + 1 );
console.log("test selfref 2:", test);

And the output I get:

"start:" Tue May 31 2011 13:09:13 GMT-0400 (EDT)
"test1:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Wed Jun 01 2011 13:09:13 GMT-0400 (EDT)
"test2:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Sat Jul 02 2011 13:09:13 GMT-0400 (EDT)
"test3:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Mon Aug 01 2011 13:09:13 GMT-0400 (EDT)
"test reset 1:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Wed Jun 01 2011 13:09:13 GMT-0400 (EDT)
"test reset 2:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Wed Jun 01 2011 13:09:13 GMT-0400 (EDT)
"test reset 3:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Thu Jun 02 2011 13:09:13 GMT-0400 (EDT)
"test selfref 1:" Wed Jun 01 2011 13:09:13 GMT-0400 (EDT)
"test selfref 2:" Thu Jun 02 2011 13:09:13 GMT-0400 (EDT)

So you can see that test1-3 the original date object remains the same, but the test object which should always be the original date + 1 day – goes all over the place.

Subsequently the reset tests and the selfref tests seem to work as expected.

Is this a bug or am I misunderstanding something?

felix

  • 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-22T22:54:03+00:00Added an answer on May 22, 2026 at 10:54 pm

    You keep adding 32 days from the date.getDate()+1

    If you change to

    var test = new Date();
    test.setDate( test.getDate() + 1 );
    console.log("test1:", date, test);
    test.setDate( test.getDate() + 1 );
    console.log("test2:", date, test);
    test.setDate( test.getDate() + 1 );
    console.log("test3:", date, test);
    

    You get

    start: Date {Tue May 31 2011 19:21:34 GMT+0200 (CEST)}
    test1: Date {Tue May 31 2011 19:21:34 GMT+0200 (CEST)} Date {Wed Jun 01 2011 19:21:34 GMT+0200 (CEST)}
    test2: Date {Tue May 31 2011 19:21:34 GMT+0200 (CEST)} Date {Thu Jun 02 2011 19:21:34 GMT+0200 (CEST)}
    test3: Date {Tue May 31 2011 19:21:34 GMT+0200 (CEST)} Date {Fri Jun 03 2011 19:21:34 GMT+0200 (CEST)}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.