Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have dropdownlist as follows


Batch start date Dropdownlist1(Date) Dropdownlist2(month) Dropdownlist3(year)

Issue date Dropdownlist4(Date) Dropdownlist5(month) Dropdownlist6(year)



String startdate;
DateTime Batchstartdate;

startdate = this.Dropdownlist1.Text.ToString().Trim() + "-" + this.Dropdownlist2.Text.ToString().Trim() + "-" + this.Dropdownlist3.Text.ToString().Trim();
Batchstartdate = Convert.ToDateTime(startdate.ToString());

string issuedate;
DateTime Batchissuedate;

issuedate = this.Dropdownlist4.Text.ToString().Trim() + "-" + this.Dropdownlist5.Text.ToString().Trim() + "-" + this.Dropdownlist6.Text.ToString().Trim();
Batchissuedate = Convert.ToDateTime(issuedate.ToString());


i want to validate issue date is not less than start date.

for that how can i validate using csharp.


if (startdate.ToString() < issuedate.ToString())
{
Label23.Text = "Start Date must be greater than the Issue date";
return;
}

when i run shows error as follows
Operator '<' cannot be applied to operands of type 'string' and 'string'


for that how can i do using cshrp.

Please help me.

Regards,
Narasiman P.
Posted
Comments
phil.o 19-Sep-13 3:59am    
Why not using a DateTimePicker instead?

Hi, you can use the < operator on DateTime itself:

C#
if (startdate < issuedate)
 {
 Label23.Text = "Start Date must be greater than the Issue date";
 return;
 }
 
Share this answer
 
Have a look at the DateTime.Compare method.

Then you could do something like:

C#
if(DateTime.Compare(Batchissuedate, Batchstartdate)>0)
{
    Label23.Text = "Start Date must be greater than the Issue date";
}
 
Share this answer
 
v2
Comments
[no name] 22-Sep-13 10:23am    
if (startdate < issuedate)
{
Label23.Text = "start date must not be less than the issue date";
return;
}

when i run the above code shows error as follows

Operator '<' cannot be applied to operands of type 'string' and 'string'

please help me.
hypermellow 23-Sep-13 3:58am    
Hi,

I've updated my solution above to pass your date variables into the DateTime.Compare method.

Give it a try and let me know how you get on?
Hi,

In your code startdate and issuedate are two strings so we compare those two dates so compare your

Batchstartdate and Batchissuedate.

if(Batchstartdate <batchissuedate)>
{
Label23.Text = "Start Date must be greater than the Issue date";

}
 
Share this answer
 
C#
if (startdate.ToString() < issuedate.ToString())
{
Label23.Text = "Start Date must be greater than the Issue date";
return;
}



just remove the .ToString() function from the condition then you code will work fine.
otherwise use this
C#
DateTime dt = Convert.ToDateTime("09/24/2013");

           if (DateTime.Compare(DateTime.Now,dt)>0)
           {
               Console.WriteLine("small");
           }
 
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