how to get time difference

  • Thread starter Thread starter Jassim Rahma
  • Start date Start date
J

Jassim Rahma

I have the following dates:

17:03:2008 21:15:58
19:47:2008 13:07:07


and i want to get the time difference between the two dates in the
following formats:

1. int format, for example: 9,253 minutes
2. hh:mm format, for example: 18:17 or even 218:17


Many Thanks,
Jassim Rahma
 
?? 19:47:2008 ??

Something like below perhaps:

DateTime dt1 = DateTime.Parse("17/03/2008 21:15:58"),
dt2 = DateTime.Parse("19/07/2008 13:07:07");

TimeSpan delta = dt2 - dt1;

string foo = ((int)Math.Floor(delta.TotalMinutes)).ToString(),
bar = string.Format("{0}:{1}",
(int)Math.Floor(delta.TotalHours), delta.Minutes);

Marc
 
Marc said:
Something like below perhaps:

DateTime dt1 = DateTime.Parse("17/03/2008 21:15:58"),
dt2 = DateTime.Parse("19/07/2008 13:07:07");

TimeSpan delta = dt2 - dt1;

string foo = ((int)Math.Floor(delta.TotalMinutes)).ToString(),
bar = string.Format("{0}:{1}",
(int)Math.Floor(delta.TotalHours), delta.Minutes);

I would drop the Math.Floor and use {1,00} ...

Arne
 
I would drop the Math.Floor

Fair enough - I'm just too lazy to remember all the different rounding
rules; by making it explicit it means I don't have to think to often ;-
p

(especially when re-visiting an old bit of code)

Marc
 
Back
Top