0

How to validate Start date and End Date using Struts2+ Jquery, where end date should be larger than start date. I have the following snippet

<div class="fb_pbdate">
  <label>Start Date<span>*</span></label><span>
  <sj:datepicker name="date" id="startdate"  value="%{new java.util.Date()}" 
    displayFormat="dd/mm/yy" timepicker="true" timepickerShowSecond="false" 
    timepickerSecondText="false" timepickerFormat="hh:mm"
    minDate="0" readonly="true" />
  <span id="start_ht1" class="fb-error"></span></span>
</div>

<div class="fb_pbdate">
  <label>Due Date<span>*</span></label><span>
  <sj:datepicker name="enddate" id="enddate"  value="%{new java.util.Date()}" 
    displayFormat="dd/mm/yy" timepicker="true" timepickerShowSecond="false" 
    timepickerSecondText="false" timepickerFormat="hh:mm"
    minDate="0" readonly="true" />
  <span id="enddate_ht2" class="fb-error"></span></span>
</div>
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Gablu
  • 139
  • 3
  • 5
  • 13

1 Answers1

0

1)do all the thing with Moment.js

2)see Compare two dates in JavaScript it will helpful for you and

3) you can help by date.js plugin

Try using DateJS, an open-source JavaScript Date Library that can handle pretty much everything! The following example is working:

<script type="text/javascript" src="date.js"></script>
<script>

    startdate = "2009-11-01";
    enddate  = "2009-11-04"; 

    var d1 = Date.parse(startdate);
    var d2 = Date.parse(enddate) ;

    if (d1 < d2) {
        alert ("Error!");
    }

</script>
Community
  • 1
  • 1
Rituraj ratan
  • 10,260
  • 8
  • 34
  • 55
  • if (Date.parse($("#enddate").val()) < Date.parse($("#startdate").val())) { alert("Invalid Date Range! Start Date cannot be after End Date!"); return false; } I use that one but its not working – Gablu Oct 04 '13 at 04:25
  • have you include date.js – Rituraj ratan Oct 04 '13 at 04:26
  • Yes,its showing the alert message in Firefox but not in Chrome and IE – Gablu Oct 04 '13 at 04:30
  • have you see http://stackoverflow.com/questions/1657733/compare-two-dates-in-javascript this link i give my answer from this link it will helpful for u and see your file order and if you can use http://momentjs.com/ then it will good for you moment.js work for all browser even in ie i am using it ... and feel happy hope it will work for you – Rituraj ratan Oct 04 '13 at 04:33