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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:12:21+00:00 2026-05-27T01:12:21+00:00

I am just starting with dateJS and it seems like a great lib but

  • 0

I am just starting with dateJS and it seems like a great lib but I am obviously missing something (probably a stupid mistake) but in my function I need 3 dates: clickedDate, weekStart & weekEnd. But using dateJS I seem to be overwritting each variable. Can someone please point out my mistake?

var clickDate = myDate;
    console.log(clickDate);
var weekStart = Date.parse(clickDate).last().monday();
    console.log(clickDate);
var weekEnd = Date.parse(clickDate).next().sunday();
    console.log(weekEnd);

console.log('break');   

console.log(clickDate);
console.log(weekStart);
console.log(weekEnd);

The console shows the following

Date {Wed Nov 30 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Mon Nov 28 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
break
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
  • 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-27T01:12:22+00:00Added an answer on May 27, 2026 at 1:12 am

    This isn’t an issue with Datejs, but a feature(?) of JavaScript Date objects. In JavaScript, the Date object is mutable, and setting a Date object value to a new variable creates a reference to the original, not a new object.

    This can be demonstrated using plain old JavaScript (no Datejs):

    Exmaple

    var a = new Date(2011, 0, 1);
    var b = a;
    var c = b;
    
    console.log('a', a); // 1-Jan-2011
    console.log('b', b); // 1-Jan-2011
    console.log('c', c); // 1-Jan-2011
    
    // setting only 'a' will cause 'b' and 'c' to update as well.
    a.setDate(10);
    
    console.log('a', a); // 10-Jan-2011
    console.log('b', b); // 10-Jan-2011
    console.log('c', c); // 10-Jan-2011
    

    The way to work around this if using Datejs is by “cloning” the Date objects. The following sample demonstrates the use of the .clone() function on the ‘b’ and ‘c’ Date objects.

    Example

    var a = new Date(2011, 0, 1);
    var b = a.clone(); // clone creates a new 'copy' of 'a'.
    var c = b.clone();
    
    console.log('a', a); // 1-Jan-2011
    console.log('b', b); // 1-Jan-2011
    console.log('c', c); // 1-Jan-2011
    
    a.setDate(10);
    
    console.log('a', a); // 10-Jan-2011
    console.log('b', b); // 1-Jan-2011
    console.log('c', c); // 1-Jan-2011
    

    Running the above, you should see the final results of ‘b’ and ‘c’ still reflect their original values even though ‘a’ has changed.

    Hope this helps.

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

Sidebar

Related Questions

Just starting out, this should be a simple one but I haven't been able
Just starting out with my first commercial app for the iStore but dont have
Just starting to use Cruise Control, but can't seem to find anything on this
Just starting to use Ruby on Rails to see what its like. I have
Just starting out with LINQ to SQL (you can probably tell - be gentle).
Just starting with php and sorry if this is a newbie question but i'm
Just starting to use CodeIgniter, and I'd like to import some of my old
Just starting out with jQuery and this problem seems to be impossible to me.
Just starting programming, so don`t kick too hard, question is pretty self explanatory, but
Just starting out with ArcGIS server at work, I've had no prior experience but

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.