Difference between two dates

Thread: Difference between two dates

1. Senior Member
Join Date
Dec 1969
Posts
156

Difference between two dates

I have a form that schedules events. They have a start date and an end date. If the difference between the start and the end is over 40 days I need it to be rejected. This is my test function:<BR><BR>function checkrequired(which) {<BR> var days<BR> days = (which.EndDate.value - which.StartDate.value)<BR> days = (days * 1000 * 60 * 60 * 24)<BR> if(days &#062; 40) <BR> {<BR> alert(&#039;Are you expecting a flood. Events should not take more than 40 days.&#039;);<BR> return false;<BR> }<BR> return true;<BR>}<BR><BR>

2. Darren Neimke Guest

RE: Difference between two dates

You could take a look at this function...<BR><BR> http://www.flws.com.au/showusyourcode/codeLib/code/js_DateDiff.asp?CatID=2<BR><BR>And see if that is what you are after.<BR><BR><BR>HTH<BR>Darren<BR>[ showusyourcode@hotmail.com ]

3. Senior Member
Join Date
Dec 1969
Posts
156

RE: Difference between two dates

Thanks for the help

4. Senior Member
Join Date
Dec 1969
Posts
96,118

Just incidentally...

Darren&#039;s answer is surely better.<BR><BR>But you brought your own bug upon yourself!<BR><BR>Suppose that your first statement produce a result of 1:<BR>&nbsp; &nbsp; days = (which.EndDate.value - which.StartDate.value)<BR><BR>Now your second statement *MULTIPLIES* that silly little 1:<BR>&nbsp; &nbsp; days = (days * 1000 * 60 * 60 * 24)<BR><BR>Producing a result of around 80,000,000 !!!<BR><BR>Well, gee, NO WONDER you can&#039;t get any count of days less than 40!<BR><BR>*APPARENTLY* you are expecting that your first line will give you the number of *milliseconds* between the two dates, yes?<BR><BR>Ummm...okay, so suppose you got 80,000,000 milliseconds. Would you then MULTIPLY that by ANOTHER 80,000,000 times????<BR><BR>I don&#039;t THINK so. <BR><BR>Ever heard of dividing?<BR>&nbsp; &nbsp; days = days / (1000 * 60 * 60 * 24)<BR><BR><BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
156

Thanks Bill

twas the end of a long day. My bad. Thanks Bill.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•