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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

datetime differences 4
Advanced IF Formula help needed 3
difference (in days) of two dates 1
xml, DateTime conversions and DateTime fields 2
Q: DateTime Difference 1
DateTime 5
DateDiff 1
DateTime 1

Back
Top