2012-06-09 275 views
-1

如何檢查日期是大於或等於日期比較

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

0%接受... – Nope

+1

請閱讀:http://stackoverflow.com/faq#howtoask並標記您的問題的答案。 –

+0

我該如何改善這個問題,由於負面 – user1196392

回答

1

DateTime.Compare()是我能想到的最簡單的方法。

7

如何

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 
+0

這是行不通的 – user1196392

+0

@ user1196392:哪一個'> ='或'比較' –

+0

如何實現小於或者大於零.plz寫if條件 – user1196392