Results 1 to 2 of 2

Thread: compare dates in javascript

  1. #1
    Join Date
    Jul 2013

    Question compare dates in javascript

    I am trying to validate date based on date entered in first textbox. If second textbox exceeds one year from the date entered in first textbox, then it should display an alert and blank the second date field textbox. Both the textboxes are readonly and gets the values from calender. I tried the below code and it is not validating if second textbox value is greater than one year. Any help !

    PHP Code:
      function test()
    start document.getElementById('name3').value;
    end document.getElementById('name4').value;

    parseDate(input) {
    parts input.match(/(\d+)/g);
                return new 
    Date(parts[2], parts[0]-1parts[1]); // months are 0-based. Parts2 contains year, parts0 contains month and parts1 contains date.
    parse_sDate parseDate(sDate);
    parse_eDate parseDate(eDate);
    parse_sDate.setDate(parse_sDate.setFullYear(parse_sDate.getMonth() + 12));
    alert("End date should not be greater than one year from start date");
    <td><input type="text" name="soname3" id="name3" size="15" readonly="readonly"> 
    <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
     <td><input type="text" name="soname4" id="name4" size="15" readonly="readonly">
     <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12'); " /> </td>
    <input type="submit" value="Submit" onclick="test()">

  2. #2
    Join Date
    Mar 2007
    Sounds like a homework assignment.

    A pointer is to calculate a year as milliseconds.

    Add that to the initial time, convert the second date to milliseconds and then if second date <= then its within the year.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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