faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 13 people (46%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

how can i find the days difference, between 2 dates in javascript???......

Apr 5th, 2008 20:30
ha mo, Colin Fraser, Ram kathir, http://www.merlyn.demon.co.uk/js-dates.htm


This is the basic script 
<script type="text/javascript"><!--
function UNIXday(D) { return Date.UTC(D[0], D[1]-1, D[2])/86400000 }
function DiffYD(S2, S1) {
 var D2 = ReadISO8601date(S2) ; if (D2<0) return "Date 1 bad"
 var D1 = ReadISO8601date(S1) ; if (D1<0) return "Date 2 bad"
 var DY = D2[0]-D1[0]
 if ( (D2[1]<D1[1]) || ( (D2[1]==D1[1]) && (D2[2]<D1[2] ) ) ) DY--
 D1[0] += DY
 return [ DY, UNIXday(D2)-UNIXday(D1) ] }
function Lo() { with (document.forms['Form6']) {
 Diff.value = DiffYD(Date1.value.trim(), Date2.value.trim())
 Date1.focus() } }
//--></script>
You can get a more full explanation at 
http://www.merlyn.demon.co.uk/js-dates.htm#diff
Good luck.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com