473,473 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to calculate the Time Difference between two dates

4 New Member
Hello,
I have been trying to calculate the difference between two date and display the difference in hours and minutes (HH:MM). I can't get it calculate properly and I can't hours and minutes to display.

I tried "results=enddate-startdate" dates have month, day, year,and time of day. After this calculation I end up with no results.
Any help would be appreciated.

Walt
May 20 '07 #1
7 54899
ADezii
8,834 Recognized Expert Expert
Hello,
I have been trying to calculate the difference between two date and display the difference in hours and minutes (HH:MM). I can't get it calculate properly and I can't hours and minutes to display.

I tried "results=enddate-startdate" dates have month, day, year,and time of day. After this calculation I end up with no results.
Any help would be appreciated.

Walt
I'll illustrate 1 Method by code:
Expand|Select|Wrap|Line Numbers
  1. Dim dteStartDateTime As Date, dteEndDateTime As Date
  2. dteStartDateTime = #5/20/2007 7:00:00 AM#
  3. dteEndDateTime = #5/20/2007 11:15:00 AM#
  4.  
  5. Debug.Print "Difference in Hours: " & DateDiff("h", dteStartDateTime, dteEndDateTime)
  6. Debug.Print "Difference in Minutes: " & DateDiff("n", dteStartDateTime, dteEndDateTime) - _
  7.             (DateDiff("h", dteStartDateTime, dteEndDateTime) * 60)
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Difference in Hours: 4
  2. Difference in Minutes: 15
May 20 '07 #2
walt
4 New Member
Adezii,
Thanks for the tip! I tried it and it works but my problem is combining the hours and minutes (HH:NN) in records. ex: 4:05, 12:14, etc
I tried to divide the total minutes by 60 but I don't get a remainer. The application is, the time is entered in severalrecords for a job, then I want to be able to sum the hours and minutes from the records and get total time (hours:minutes) for the job.
Thank again



I'll illustrate 1 Method by code:
Expand|Select|Wrap|Line Numbers
  1. Dim dteStartDateTime As Date, dteEndDateTime As Date
  2. dteStartDateTime = #5/20/2007 7:00:00 AM#
  3. dteEndDateTime = #5/20/2007 11:15:00 AM#
  4.  
  5. Debug.Print "Difference in Hours: " & DateDiff("h", dteStartDateTime, dteEndDateTime)
  6. Debug.Print "Difference in Minutes: " & DateDiff("n", dteStartDateTime, dteEndDateTime) - _
  7.             (DateDiff("h", dteStartDateTime, dteEndDateTime) * 60)
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Difference in Hours: 4
  2. Difference in Minutes: 15
May 21 '07 #3
missinglinq
3,532 Recognized Expert Specialist
So after calculating the two, you need to concatenate them:

Expand|Select|Wrap|Line Numbers
  1. TimeDifference =  [Difference in Hours] & ":" & [Difference in Minutes]
May 21 '07 #4
ADezii
8,834 Recognized Expert Expert
Adezii,
Thanks for the tip! I tried it and it works but my problem is combining the hours and minutes (HH:NN) in records. ex: 4:05, 12:14, etc
I tried to divide the total minutes by 60 but I don't get a remainer. The application is, the time is entered in severalrecords for a job, then I want to be able to sum the hours and minutes from the records and get total time (hours:minutes) for the job.
Thank again
  1. missingling has the correct response about concatenating both differences.
  2. Look at the code again, you are not dividing by 60. To get the Minutes component you are calculating the total number of minutes difference - (minus) the number of Hours difference * 60.
May 21 '07 #5
sansaniwal
3 New Member
  1. missingling has the correct response about concatenating both differences.
  2. Look at the code again, you are not dividing by 60. To get the Minutes component you are calculating the total number of minutes difference - (minus) the number of Hours difference * 60.


Query will be like as :------------
db2 "select substr(HOSTNAME,1,25) as hostname,ltrim(rtrim(char(timestampdiff(8,char(tim estamp(CLOSETIME)-timestamp(STARTTIME)))))) ||':' || char((int(
ltrim(rtrim(char(timestampdiff(4,char(timestamp(CL OSETIME)-timestamp(STARTTIME))))))))- ( int( ltrim(rtrim(char(timestampdiff(8,char
(timestamp(CLOSETIME)-timestamp(STARTTIME)))))))*60)) as difftime from EVENTS_TIME"
May 29 '07 #6
satiss7pwr
41 New Member
plese will u post this code in c# plssssssssssssssssss
Feb 27 '10 #7
ADezii
8,834 Recognized Expert Expert
This sounds like a question for the C# Forum, not here.
Feb 27 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be...
4
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
5
by: SimonC | last post by:
Help needed for a Javascript beginner. As above in the subject... i need a javascript to run this, but not in the form of a web-page. I want to calculate it between 2 fields in a database that...
2
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates:...
5
by: infobescom | last post by:
Hi I am wrking on a application where i need to calculate the difference between two dates .. here is the formula i am using ........ Public Function GetNumberOfWorkDays(sStartDate,...
4
by: lenygold via DBMonster.com | last post by:
I found this example in MYSQL: create table events ( id integer not null primary key , datetime_start datetime not null , datetime_end datetime not null ); insert into events values ( 1,...
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...
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.