c#中的日期比较

时间:2012-06-09 12:57:13

标签: c# c#-4.0

在c#4.0中,如何在文本框中查看日期,日期大于等于

DateTime StartDate =  Convert.ToDateTime(TxtStrtDate.Text);
DateTime ExpirationDate = Convert.ToDateTime(TxtExpDte.Text);

由于

2 个答案:

答案 0 :(得分:8)

怎么样

bool b = ExpirationDate >= StartDate;

阅读此DateTime.GreaterThanOrEqual Operator

OR

int i = DateTime.Compare(ExpirationDate, StartDate);

//if ExpirationDate is less than StartDate then result is Less than zero

//if ExpirationDate equals StartDate then result is Zero

//if ExpirationDate is greater than StartDate then result is Greater than zero

答案 1 :(得分:2)

DateTime.Compare()是我能想到的最简单的方式。