datetime diff

  • Thread starter Thread starter SenthilVel
  • Start date Start date
S

SenthilVel

HI

how to get the differences between 2 given dates??

supposse if i ahve 2 dates , DATEa, and current datetime.

how can i find if the DATEa is less then 3 hrs from the current datetime ???


,,,,
Senthil
 
DateTime a = DateTime.Now.AddHours(3);
DateTime b = DateTime.Now;

// Subtracts the dates
TimeSpan c = a.Subtract(b);
 
Vko said:
DateTime a = DateTime.Now.AddHours(3);
DateTime b = DateTime.Now;

// Subtracts the dates
TimeSpan c = a.Subtract(b);

and then compare it with TimeSpan.FromHours(3).
With C# you can compare using the "<" operator,
or you can use the TimeSpan.Compare(..) method.

Or (a step less), use the DateTime.Compare(..) method.

Hans Kesting
 
Back
Top