Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have Date from (mm/dd/yyyy) and Date To (mm/dd/yyyy).
Date from: 3 textboxes for MM, DD, YYYY respectively
Date to : 3 textboxes for MM, DD, YYYY respectively
Can anyone help me how to compare validate these two dates? Can anybody please provide code to it.

Thank You,
Krish
Posted
Comments
koool.kabeer 2-Aug-10 15:03pm    
cant you use three compare validators?
one for MM...
one for DD..
one of YYYY...
koool.kabeer 2-Aug-10 15:04pm    
are you allowing user to type the text in Textboxes?
or You are just setting the Texts with Calendar Control...
venkatesh_krish 2-Aug-10 15:08pm    
allowing user to type in textboxes
William Winner 2-Aug-10 15:20pm    
don't post an answer that isn't an answer!

I went ahead and deleted your fake answer.

Have you even looked at the DateTime class in C#?

One of the constructors is:

VB
public DateTime(
    int year,
    int month,
    int day
)


So, create two DateTimes and compare them however you're going to compare them. You can use DateTime.CompareTo(DateTime).

This is pretty simple stuff and next time I would suggest starting by googling "compare to Dates in C#".
 
Share this answer
 
Comments
venkatesh_krish 2-Aug-10 15:07pm    
can you please clearly write the code..iam just starter..thank you
William Winner 2-Aug-10 15:18pm    
yes I can. But I will not. These are things you need to find a book to read up on or pay for a class somewhere. This web site isn't meant to be as a tutorial for all wannabe programmers. If you're a starter, then you need to start with something structured, and not just trying to figure it out as you go.

As a side note, looking at the other comments, you also need to make sure that you're checking what the user is typing in the TextBoxes. I will help you with a workflow, but you need to figure out how to accomplish it on your own.

1.)Check that what was typed in the boxes is appropriate (ie. for Month that it's an integer between 1 and 12.)
2.)Create the DateTimes
3.)Compare the DateTimes
4.)Do something based on the result of the comparison.
venkatesh_krish 2-Aug-10 15:22pm    
Thank You
Yusuf 2-Aug-10 17:59pm    
Reason for my vote of 5
Give a man a fish and he will have a dinner.
Show and man how to fish and ....
Why can't you use date control. If you want to stick to text boxes then take the date from all the text boxes and use various IF conditions to compare them... :-D
 
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