i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How I compare two dates in C#?
09-27-2010, 04:35 AM
Post: #1
How I compare two dates in C#?
DateTime.Compare Method in C# :
Suppose you have two textbox with datepicker now you want to compare two dates:
Code:
datetime dt1;
datetime dt2;
dt1 = Convert.todatetime(txtFromDate.text.trim());
dt2 = Convert.todatetime(txtToDate.text.trim());
Code:
DateTime date1 = new DateTime(dt1.year, dt1.month, dt1.day);
DateTime date2 = new DateTime(dt2.year, dt2.month, dt2.day);
int result = DateTime.Compare(date1, date2);
string relationship=string.Empty;

if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";        
else
   relationship = "is later than";




Please give reputation if my answer/post is useful for you
Best Regards
Arti Gupta
Quote
10-02-2010, 01:41 AM
Post: #2
RE: How I compare two dates in C#?
(09-27-2010 04:35 AM)arti.porwal20@gmail.com Wrote:  DateTime.Compare Method in C# :
Suppose you have two textbox with datepicker now you want to compare two dates:
Code:
datetime dt1;
datetime dt2;
dt1 = Convert.todatetime(txtFromDate.text.trim());
dt2 = Convert.todatetime(txtToDate.text.trim());

MSDN Link

Two Busy Days..

Thanks and Regards
Raju.M
Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  One compare strings in C# Shafiur Rahman 0 583 09-23-2010 10:46 AM
Last Post: Shafiur Rahman



User(s) browsing this thread: 1 Guest(s)