How to compare DateTime in C#? Ask Question

How to compare DateTime in C#? Ask Question

I don't want user to give the back date or time.

How can I compare if the entered date and time is LESS then the current time?

If the current date and Time is 17-Jun-2010 , 12:25 PM , I want user cannot give date before 17 Jun -2010 and time before 12:25 PM.

Like my function return false if the time entered by user is 16-Jun-2010 and time 12:24 PM

ベストアンサー1

Microsoft has also implemented the operators '<' and '>'. So you use these to compare two dates.

if (date1 < DateTime.Now)
   Console.WriteLine("Less than the current time!");

おすすめ記事