Date Comparison in javascript
<script type="text/javascript"> function FromDate(getID) { document.getElementById('SalesEndDate').value = ""; var dateString = document.getElementById(getID).value; var target = new Date(dateString); var now = new Date; if(now<=target) { return true; } else { alert("Starting date must be current or future date."); document.getElementById(getID).value = ""; return false; } } function ToDate(getID) { var dateString = document.getElementById(getID).value; var toDate1 = new Date(dateString); var datestring1 = document.getElementById('SalesFromDate').value; var FromDate = new Date(datestring1); if(FromDate<=toDate1) { return true; } else { alert("End date must be Start or future date."); document.getElementById(getID).value = ""; return false; } } </script>
There are two functions fromdate and todate which accept the parameter as an id of the text field.
<script type="text/javascript"> function FromDate(getID) { document.getElementById('SalesEndDate').value = ""; var dateString = document.getElementById(getID).value; var target = new Date(dateString); var now = new Date; if(now<=target) { return true; } else { alert("Starting date must be current or future date."); document.getElementById(getID).value = ""; return false; } } function ToDate(getID) { var dateString = document.getElementById(getID).value; var toDate1 = new Date(dateString); var datestring1 = document.getElementById('SalesFromDate').value; var FromDate = new Date(datestring1); if(FromDate<=toDate1) { return true; } else { alert("End date must be Start or future date."); document.getElementById(getID).value = ""; return false; } } </script>
Comments
Leave a Comment