Comparing date problems

Results 1 to 2 of 2

Thread: Comparing date problems

  1. #1
    Join Date
    Dec 1969

    Default Comparing date problems

    I am trying to compare dates in the following way.<BR><BR>var nextpaydate = document.myform.nextpaydate.value; <BR>var mydate = opener.document.payment.date1.value;<BR>var mydate = new Date(mydate)<BR>var nextdate = new Date(nextpaydate)<BR>var mynewdate = mydate.getMonth()+1 +&#039;/&#039;+ mydate.getDate() +&#039;/&#039;+ mydate.getYear()<BR>var mynextdate = nextdate.getMonth()+1 +&#039;/&#039;+ nextdate.getDate() +&#039;/&#039;+ nextdate.getYear()<BR><BR>this works fine, it gives me 2/06/2003, etc.<BR><BR>Now when I compare dates such as <BR><BR>if (mynewdate &#062; mynextdate)<BR><BR>it works good, but when one of the dates MONTHS is 2-digits like 10,11,12 the compare does not work. the above if statement returns false.<BR><BR><BR>Can anyone help me figure out what I am doing wrong.

  2. #2
    Join Date
    Dec 1969

    Default RE: Comparing date problems

    Use this function for date validation..<BR><BR><BR> function validateDates(d1,d2){<BR> <BR> if (d1 != ""){<BR> date1 = formDate(d1);<BR> if (!date1)<BR> return false;<BR> }<BR> if (d2 != ""){<BR> date2 = formDate(d2);<BR> if(!date2)<BR> return false;<BR> }<BR> <BR> <BR> if (d1 != "" && d2 != ""){<BR> var difference = date2.getTime() - date1.getTime();<BR> if (difference &#060; 0 ){<BR> alert("End date cannot be prior to Start Date");<BR> <BR> return false;<BR> }else{<BR> return true;<BR> }<BR> }else{<BR> return true;<BR> }<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