homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

having trouble creating a valid date object
need to set up dates and then do the difference
Baruch Menachem

5+ Year Member

Msg#: 4463275 posted 5:41 am on Jun 9, 2012 (gmt 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!")



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

Msg#: 4463275 posted 1:39 pm on Jun 11, 2012 (gmt 0)

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.


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

Msg#: 4463275 posted 5:25 pm on Jun 11, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved