Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have three DateTime variables date1,date2,date. Now i want to compare it in if clause.

If date1 between date2 and date3, message box should be shown date1 is between date1 and date2..

question is how to use between clause in c#??
Posted

Try:
C#
DateTime firstDate = new DateTime(2013, 1, 1);
DateTime myDate = DateTime.Now;
DateTime secondDate = new DateTime(2013, 12, 31);
if (myDate >= firstDate && myDate <= secondDate)
   {
   MessageBox.Show("date1 is between date1 and date2.");
   }
 
Share this answer
 
Use

DateTime.Compare Method

For more info
http://msdn.microsoft.com/en-us/library/system.datetime.compare.aspx[^]
 
Share this answer
 

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