Reputation: 2822
I am comparing two DateTime
s to see if there is 10 or fewer minutes between them. If I do DateTimeA - DateTimeB
, and A
is on 4/1/13 and B
is on 4/3/13 I won't get the desired results.
I am only worried about minutes. So DateTimeA
takes place at 8:00 am and DateTimeB
takes place at 12:20 pm, I would want the result to be 260 minutes.
Upvotes: 2
Views: 157
Reputation: 8488
(DateTimeA - DateTimeB).TotalMinutes % 24*60
Get the total number of minutes modulo the number of minutes in a day. That way you'll get rid of the different-day problem.
Upvotes: 6
Reputation: 881
(A - B).TotalMinutes
A-B will yield a Timespan, for which the total minutes can then be produced.
Upvotes: -1
Reputation: 1698
You will need to use DateTime.TimeofDay()
To get the actual time values and then do arithmatic on them.
or use DateTime.Minute
DateTime.Hour
DateTime.Second
. Here is a full explanation on DateTime
objects: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
Upvotes: 4