471,349 Members | 1,137 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

how to get time difference

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

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
3 4225
?? 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
Jun 27 '08 #2
Marc Gravell wrote:
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
Jun 27 '08 #3
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
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jason Reljac | last post: by
2 posts views Thread by Joe User | last post: by
6 posts views Thread by Michael Bulatovich | last post: by
5 posts views Thread by Geoff Jones | last post: by
3 posts views Thread by Randall Parker | last post: by
3 posts views Thread by Steve | last post: by
15 posts views Thread by student4lifer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.