Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

having trouble creating a valid date object

need to set up dates and then do the difference

5:41 am on Jun 9, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Mar 26, 2008
posts: 127
votes: 0

I want to set up a pair of date objects to operate on, but the objects i create are invalid. Can anyone tell me what mistake I am making in creating my date objects?


// get the number of days for each month

if (rangeCheck(dayy1,pesach1)&&rangeCheck(dayy2,pesach2))
// do range checks for each month
mnt1--;// the date function runs from 0-11. months are numbered 1-12.
mnt2--;//adjust the month values to fit the javascript function
[b] lday = new Date(yr1,mnt1,dayy1,12,12,12,12);[/b] //create a new date object for each part of the problem

rday=new Date(yr2,mnt2,dayy2,12,12,12,12);
alert(lday.toDateString()+" "+rday.toDateString())
//Calculate difference btw the two dates, and convert to days
//" days left until Christmas!")
1:39 pm on June 11, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 5007
votes: 21

I think there is too much information missing from your example to be much help. For example, we don't know what dey1, dey2, m1, m2, yr1, and yr2 are. We also don't know what howmany and rangeCheck are doing.
5:25 pm on June 11, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

You have to set the difference variable as a date object too. It's grossly out of context, but here's a piece I'm using for a daily time sheet calculator. Basically all I'm doing is getting a start and end time and determining the difference.

sdt= new Date(); // start
edt= new Date(); // end
diff= new Date(); // difference

// This app is JUST for hours/minutes, so I just hard coded a fake year/m/d into it.

datetemp = new Date('01/01/2000 ' + astart_hr + ':' + astart_min + ':00');
end_day = (aend_hr < astart_hr)?'01/02/2000':'01/01/2000';
datetemp = new Date(end_day + ' ' + aend_hr + ':' + aend_min + ':00');
diff.setTime(Math.abs(edt.getTime() - sdt.getTime()));
minutes = Math.floor(diff.getTime() / (1000 * 60));

I then go on to break minutes into hours, etc.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members