"andyoye" <an*****@nospam .comwrote in message
news:eD******** ******@TK2MSFTN GP03.phx.gbl...
how about time difference to the minutes? below date and time values are
entered by users in text fields.
So startDate = 10-01-2008 startEnd= 2:05 PM
endDate = 10-03-2008 endTime = 1:00 PM
result should be 1days 22 hrs 55mins
[Sorry for the late reply; I forgot I started following this group!]
The best thing to do is to get the difference between the dates in the
smallest possible unit you're looking for (minutes in this case) and then
apply math to extract the larger units. For example, you've got 2815 minutes
there. You make some constants like
private const int MINUTES_PER_DAY = 1440
private const int MINUTES_PER_HOU R = 60 // Yes, this one might be
overkill....
and then you test your value against them. If you have more than the
constant, then you've got at least one of that unit, so you do some integer
division to get the number of units and then you test the remainder against
the next smaller unit.
Instead of constants, you could make a class which holds the number and a
description (1440 / "days", 60 / "hrs", etc.) and then make an array or
collection of objects of that class so you could process them in a loop.
Then you could make different arrays/collections for different units
(seconds, milliseconds, etc.).