472,983 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 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 4288
?? 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason Reljac | last post by:
Howdy, For a project I am working on right now I need to be able to calculate the time difference between to given times. (For example...The difference between 11:30 am and 1:45pm being 2:15) ...
10
by: Andreas | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way...
2
by: Joe User | last post by:
I am looking to calculate the difference between and event time and a sample time of Now. This is the query that I thought would do it, however I'm returning DIFFERENCE values that look the same...
6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
6
by: Michael Bulatovich | last post by:
I have a very simple db I use for keeping track of hours, tasks, projects, clients etc. It has a form that I use to enter data. Currently the form has a textbox for a field called "start time",...
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
5
by: Geoff Jones | last post by:
Hi I have question regarding times and dates in a datatable. I have one table with one column having the date e.g.03/09/04, and another column other the time 08:03:05. The other table has one...
3
by: Randall Parker | last post by:
Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the...
3
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.