Compare two dates

Question posted in Computer Software on 04 2010
Rate question difficulty level 1 Votes
Compare two dates using no more than two if statements?
 
 
1 Answer
 
My answer would be

DateTime dt1 = new DateTime(2006, 01, 24);
DateTime dt2 = new DateTime(2006, 01, 23);

///////////first statement

if (DateTime.Compare(dt1, dt2) < 0)
Console.WriteLine("second date is larger than the first date");
///////////second statement
else if (DateTime.Compare(dt1, dt2) == 0)
Console.WriteLine("second date is same as first date");
///////////This is only the outcome - not a statement
else
Console.WriteLine("second date is smaller than the first date");

04/06/2010
 
 
Add an answer*
 
Your name
Email
 
Company: Kronos
Location: India
developer programing

add a question

arrow_blue


Now hiring!
---------------------------
---------------------------
---------------------------
---------------------------
Mercer 
---------------------------
---------------------------
---------------------------