Click here to Skip to main content
16,013,918 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
This is My Code
var txtFromDate = document.getElementById("<%=txtFromDate.ClientID%>").value;
var txtToDate = document.getElementById("<%=txtToDate.ClientID%>").value;

var D1 = new Date(txtFromDate);
var D2 = new Date(txtToDate);

if(D1 > D2)
   alert("FromDate cannot be greater than ToDate");

But Problem here is
--> txtFromDate and txtToDate are in "dd-mmm-yyyy" Date Formate (22-Jan-2011)
--> Thats why D1 and D2 vale coming as "NaN"
--> Bcoz of this I cant do comparison bw D1 & D2

--> Give me a solution so that i can convert 22-Jan-2011 format to 22-01-2011
--> Or else any other solution with respect with Date Comparison bw D1 & D2

Thank You...
Posted

Hello,

try this

C#
if (Convert.ToDateTime(txtIn.Text) > Convert.ToDateTime("1/1/2000"))
            {
                lblOut.Text = "greater then 1/1/2000";
            }
            else
            {
                lblOut.Text = "equal or less then 1/1/2000";
            }

this works for me

sanjeev
 
Share this answer
 
I believe your real issue is the format.
Here is some nice work done on Date formatting in javascript. They provide a javascript library which might be of some help.

If you can use JQuery plugins, here is one which I think will be helpful.

Hope this helps!
 
Share this answer
 
v3
Change the date format
var txtFromDate = '23/Jan/2011';//document.getElementById("<%=txtFromDate.ClientID%>").value;
var txtToDate = '22/Jan/2011';//document.getElementById("<%=txtToDate.ClientID%>").value;

var D1 = new Date(txtFromDate);
var D2 = new Date(txtToDate);
if(D1 > D2)
{
    alert("FromDate cannot be greater than ToDate");
}
else
{
  //Nothing

}
 
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