homepage Welcome to WebmasterWorld Guest from 107.22.78.233
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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




msg:4463277
 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?

Thanks

dayy1=dey1.value*1;
dayy2=dey2.value*1;
mnt1=m1.value*1;
mnt2=m2.value*1;
yr1=yr1*1;
yr2=yr2*1;
pesach1=howmany(mnt1);
// get the number of days for each month

pesach2=howmany(mnt2);
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
//document.write(Math.ceil((christmas.getTime()-today.getTime())/(one_day))+
//" days left until Christmas!")
vive=(Math.ceil((lday.getTime()-rday.getTime())));
vive=vive/one_day;

 

Fotiman




msg:4463910
 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.

rocknbil




msg:4464038
 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');
sdt.setTime(datetemp.getTime());
end_day = (aend_hr < astart_hr)?'01/02/2000':'01/01/2000';
datetemp = new Date(end_day + ' ' + aend_hr + ':' + aend_min + ':00');
edt.setTime(datetemp.getTime());
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