Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends i have problem in date comparison

in one text(Fromdate) box i given date like 2012-03-12(using date picker)

in another text(To date) box i given date like 2012-02-12(using date picker)

if to date is less than from date i have to give alert
Posted
Comments
Sergey Alexandrovich Kryukov 22-Mar-12 12:36pm    
Is this on server side (PHP) or client side (JavaScript)? Both comparisons are possible, and you tag both...
--SA

Google is your friend. The very first entry of a quick search gave me "Comparing Dates in PHP"[^].
 
Share this answer
 
C#
<script language="javascript">
function datevali()
{
    //alert('hi');
    var startdate = document.getElementById('fromdate').value;
   var enddate  = document.getElementById('amce').value;
   var todate = document.getElementById('todate').value;
   var amcs = document.getElementById('amcs').value;

   var d1 = new Date(startdate)
   var d2 = new Date(enddate)
   var d3= new Date(todate)
   var d4= new Date(amcs)
   //alert(d1);
  // alert(d2);

   if (d2 < d1) {
      alert ("Disposed Date Must be graterthan Warranty Expiry Date ") ;
                }
                if (d3 > d4) {
      alert ("Commissioned date must be grater than delivered date ") ;
                }
                if (d1 < d4) {
      alert ("Warranty Expiry Date Must be graterthan Commissioned date") ;
                }
                if (d1 < d3) {
      alert ("Warranty Expiry Date Must be graterthan delivered date") ;
                }

}
</script>




call this method in tour date picker

<input type="text" name="expirydate" id="fromdate" onchange="return datevali();"/>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900