Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how compare two textbox dates in javascript
Posted

you can convert the strings to date and then compare the two strings like this
JavaScript
var Date1 = new Date("12/121/2012");

 var Date2 = new Date("6/6/2013");



 if (Date2 > Date1)

 {

     alert('found');

 }
 
Share this answer
 
Try this code:


HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">

<title>Untitled Page</title>
<script>function date()

{
t1=document.getElementById("text1").value;

t2=document.getElementById("text2").value;

var one_day=1000*60*60*24;

var x=t1.split("/");

var y=t2.split("/");

var date1=new Date(x[2],(x[1]-1),x[0]);

var date2=new Date(y[2],(y[1]-1),y[0])

var month1=x[1]-1;
var month2=y[1]-1;

_Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day));
if(_Diff<0)

{
alert("seelct correct date");

}

}

</script>
</head> <body>

<form id="Form1" runat="server" >
<input type="text" id="text1" />

<input type="text" id="text2" />
<input type="button" value="check" onclick="date()" />

</form>
</body>

</html>
 
Share this answer
 
http://stackoverflow.com/questions/492994/compare-dates-with-javascript

check the above link.it will help you.

-anurag
 
Share this answer
 
Hello,
This may helps you

C#
function CheckValid() {

           var fromDate = $('#<%=txtFromDt.ClientID %>').val();
           var toDate = $('#<%= txtTodt.ClientID %>').val();
           if ((fromDate != "" && toDate != "") && Date.parse(fromDate) > Date.parse(toDate)) {
               // alert("To date should be greater than From date.");
               $('#<%= lblErrorMsg.ClientID %>').text('To date should be greater than From date.');
               return false;
           }
       }
 
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