1 pbm..........................

1. Member
Join Date
Dec 1969
Posts
33

## 1 pbm..........................

hi again,<BR><BR>i am trying to calculate the difference between 2 dates..<BR>how do i calculate it in javascript??<BR><BR>plz anyone help..<BR><BR>regds,<BR>mary

2. Senior Member
Join Date
Dec 1969
Posts
148

## RE: 1 pbm..........................

JavaScript as in client side? As in not ASP?<BR><BR>Research the unusually named Date object.<BR><BR>There&#039;s plenty of info about, try eg http://www.dynamicdrive.com

3. Senior Member
Join Date
Dec 1969
Posts
228

## DateDiff of course :)

Here...<BR><BR>Taken right off my javascript library :)<BR><BR>/************************************************** ************<BR> DateDiff: Returns the Difference between two dates in weeks,<BR> days, hours, minutes & seconds<BR><BR> Parameters:<BR> - Date1: First Date<BR> - Date2: Second Data<BR><BR> Returns: String containing the weeks, days, hours, minutes &<BR> seconds between the two dates.<BR>**************************************** ***********************/<BR>function DateDiff(Date1, Date2)<BR>{<BR> date1 = new Date();<BR> date2 = new Date();<BR> diff = new Date();<BR><BR> date1temp = new Date(Date1);<BR> date1.setTime(date1temp.getTime());<BR> date2temp = new Date(Date2);<BR> date2.setTime(date2temp.getTime());<BR><BR> diff.setTime(Math.abs(date1.getTime() - date2.getTime()));<BR> timediff = diff.getTime();<BR><BR> weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));<BR> timediff -= weeks * (1000 * 60 * 60 * 24 * 7);<BR><BR> days = Math.floor(timediff / (1000 * 60 * 60 * 24)); <BR> timediff -= days * (1000 * 60 * 60 * 24);<BR><BR> hours = Math.floor(timediff / (1000 * 60 * 60)); <BR> timediff -= hours * (1000 * 60 * 60);<BR><BR> mins = Math.floor(timediff / (1000 * 60)); <BR> timediff -= mins * (1000 * 60);<BR><BR> secs = Math.floor(timediff / 1000); <BR> timediff -= secs * 1000;<BR><BR> return (weeks + " weeks, " + days + " days, " + hours + " hours, " + mins + " minutes, and " + secs + " seconds");<BR>}<BR><BR>Stéphane Dorion

4. Senior Member
Join Date
Dec 1969
Posts
148

## Ok..

.. hand it on a plate why don&#039;tcha

5. Senior Member
Join Date
Dec 1969
Posts
228

## LOL, a matter of point of view

I&#039;d rather give her the full function and let her understand instead of giving her tidbits of informations here and there until she understands.<BR><BR>Besides....if the function ever crashes, she&#039;ll be stuck with it if she did not take the time to understand it.<BR><BR>LOL, if it wasn&#039;t from me, she&#039;d probably have taken it from a website anyway. This is a very common function or type of function.<BR><BR>It&#039;s not as if she had a programming problem (a puzzle) that I took upon myself to solve.<BR><BR>Stéphane Dorion<BR>-----------------------------------<BR>There are 10 types of people in the<BR>world: Those who understand binary,<BR>and those who don&#039;t. <BR>-----------------------------------

#### Posting Permissions

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