Calculate difference between two datetime values

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hello all,

I'm new in CF and C#.
How can I calculate the diffence between two datetime values, lets say :
Date1 "8/21/2004 03:20:00"
Date2 "8/20/2004 23:40:00"
and then compare this

if (Date1 - Date2) >= 15 minutes then
do something
else
do otherwise


thanks

Peter.
 
Peter said:
I'm new in CF and C#.
How can I calculate the diffence between two datetime values, lets say :
Date1 "8/21/2004 03:20:00"
Date2 "8/20/2004 23:40:00"
and then compare this

if (Date1 - Date2) >= 15 minutes then
do something
else
do otherwise

TimeSpan ts = date1-date2;

if (ts.TotalMinutes >= 15)
{
....
}
 
When you subtract two DateTime structs you get a TimeSpan result. So using
the resulting TimeSpan you can compare against the TotalMinutes property to
accomplish what you want.

--
Tim Wilson
..Net Compact Framework MVP

<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
 
Back
Top