Help Required to calculate Hours and Minutes in a Query (1 Viewer)

aftab1965

Registered User.
Local time
Today, 11:07
Joined
Jan 12, 2016
Messages
48
Dear Sir,
I want to calculate time ( Based on Start Time and End Time) in a query (Sample db is attached) I tried couple of methods to achieve the required result.
By setting up field to "Number" in Mehtod1 Table calculates as number but can't set as HH:NN. Method 2Table can't restrict input more than 60 Minutes.

Your Kind Advise/ Help are really appreciated
 

Attachments

  • Time_Calculation.accdb
    1.6 MB · Views: 232

plog

Banishment Pending
Local time
Today, 02:07
Joined
May 11, 2011
Messages
11,645
I don't understand where to start, nor end. You've dumped 3 tables and 4 queries that presumably don't work on me. Which table is the starting data? I can't help you specificaly, so in general you use the DateDiff function:


Since the smallest unit you want to use is minutes, you would get the difference in that unit, then do math to format the output like you want.
 

aftab1965

Registered User.
Local time
Today, 11:07
Joined
Jan 12, 2016
Messages
48
I don't understand where to start, nor end. You've dumped 3 tables and 4 queries that presumably don't work on me. Which table is the starting data? I can't help you specificaly, so in general you use the DateDiff function:


Since the smallest unit you want to use is minutes, you would get the difference in that unit, then do math to format the output like you want.
Thanks for replying. As I mentioned in my post that I have tried 2 methods. ( Table 1 and Table 2) but required help is as per " Required Table". Thanks if you can help me
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:07
Joined
Feb 28, 2001
Messages
27,172
Let's start with the obvious. Time2 - Time1, where both variables are Date/Time formats, will give you the time difference in Access internal time units, which are days and fractions of a day. Typically when formatting the difference, you have one of two cases.

First case: The amount of time is less than 1 full day. In that case, the difference between two date fields can be input to a regular FORMAT function using "HH:NN" as the format string.

Second case: The amount of time is more than 1 full day OR can be negative. In that case, you have to do a formatting function because the standard Access routines do not allow hours in excess of 23.

Therefore, to help you, we first need to know if your times can exceed 1 day, either individually or in summation.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:07
Joined
Feb 19, 2002
Messages
43,263
The datetime data type is a "point in time". It is NOT "elapsed time". Therefor, when you use datediff() to find the different between two dates, you can speify a unit of measure for the difference, seconds, minutes, hours, days, etc. But you don't get to specify a formatted result such as hh:mm.

I've attached a database with a number of date time functions that will help you to come up with a STRING that shows the result. Keep in mind that since the value is a string, it cannot be used to perform arithmetic.
 

Attachments

  • UsefulDateFunctions20220116.zip
    312.7 KB · Views: 244

aftab1965

Registered User.
Local time
Today, 11:07
Joined
Jan 12, 2016
Messages
48
Let's start with the obvious. Time2 - Time1, where both variables are Date/Time formats, will give you the time difference in Access internal time units, which are days and fractions of a day. Typically when formatting the difference, you have one of two cases.

First case: The amount of time is less than 1 full day. In that case, the difference between two date fields can be input to a regular FORMAT function using "HH:NN" as the format string.

Second case: The amount of time is more than 1 full day OR can be negative. In that case, you have to do a formatting function because the standard Access routines do not allow hours in excess of 23.

Therefore, to help you, we first need to know if your times can exceed 1 day, either individually or in summation.
Thanks Sir, my requirement is as per "Second Case". I'm calculating individual time which can't be a negative value and will not exceed 1 day(23:59) but in summation it will exceed 1 day. for easy understanding I attached db herewith
 

Attachments

  • Time_Calculation.accdb
    3.5 MB · Views: 244

theDBguy

I’m here to help
Staff member
Local time
Today, 00:07
Joined
Oct 29, 2018
Messages
21,467
Thanks Sir, my requirement is as per "Second Case". I'm calculating individual time which can't be a negative value and will not exceed 1 day(23:59) but in summation it will exceed 1 day. for easy understanding I attached db herewith
Did you try my suggestion? Just curious...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:07
Joined
May 7, 2009
Messages
19,233
query3 will be your final query.
 

Attachments

  • Time_Calculation.accdb
    3.6 MB · Views: 251

Users who are viewing this thread

Top Bottom