Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi friends.

i have two date value that they are stored in two string. i want to compare this two date to know greater.how can i compare this?

thank you.
Posted

1 solution

Hello,
Try this.

DateTime date1 = Convet.ToDateTime(str1);
DateTime date2 = Convet.ToDateTime(str2);
int result = DateTime.Compare(date1, date2);
string relationship;

if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";         
else
   relationship = "is later than";
 
Share this answer
 
Comments
_Starbug_ 5-Aug-14 8:26am    
thank's friend.it was good answer.that problem solved.i want a code that show me months that are in past. in the other word i want months that are early than this month that we are in it.what i must do?

thanks again.
Savalia Manoj M 6-Aug-14 9:30am    
I can not understand your question. Please explain in detail so i can help you.
_Starbug_ 6-Aug-14 10:57am    
i solved it myself. sir i want time that it is less than now. for that i must know the value of this year and value of this month. i fetched this value from mydatetime class.
thank you.

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