newrehmi Posted January 27, 2012 Share Posted January 27, 2012 hello there, I have some sort of problem with date in javascript... lemme just post my code here... var currDate = new Date();var currDateEnd = new Date(); currDateEnd = currDate;currDateEnd.setDate(currDate.getDate()+7); alert(currDate); //I tried alert currDate here, and looks like this object (currDate) value has been changed to the value of currDateEnd I know there's other way to surpass this problem, but I want to know first why this is happening... Thanks a lot, very much... Link to comment Share on other sites More sharing options...
Ingolme Posted January 27, 2012 Share Posted January 27, 2012 Objects are always referenced and not copied, so both currDate and currDateEnd are pointing to the same object because of this line: currDateEnd = currDate; You can remove that line. If you want to copy the value of a date object to a new one, do this: var currDate = new Date();var currDateEnd = new Date(currDate.getTime()); Link to comment Share on other sites More sharing options...
newrehmi Posted January 27, 2012 Author Share Posted January 27, 2012 THanks alot!!!! that help me much!! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.