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


Baruch Menachem

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

5+ Year Member

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 Jun 11, 2012 (gmt 0)

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

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 Jun 11, 2012 (gmt 0)

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

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month