short time calculations


P

p-rat

I have a form that has a start time and end time. Both are format
Short Time. I also have a option frame that is for AM or PM after each
of these fields. So a user would enter 08:00 then select AM for
example to start and then type 08:15 then select PM for a persons end
time.

This might be a stupid question, but how would I calculate this? Would
DateDiff take into account that this would be 12 hours and 15 minutes
or would it see it as only 15 minutes?

Would it be easier to just use military time 08:00 to 20:15?

I would also like the calculation value to show up on the form in a
field such as "TotalHours".

Thanks for any help to get pushed in the right direction.
 
Ad

Advertisements

A

Al Campagna

p-rat,
Using military time would allow DateDiff to work.
or
With the format for the time fields set to...
hh:nn am/pm
Users can enter
"8:15 a" to get 8:15 am
or
"8:15 p" to get 8:15 pm.
Then DateDiff would work on those values.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
J

John W. Vinson

I have a form that has a start time and end time. Both are format
Short Time. I also have a option frame that is for AM or PM after each
of these fields. So a user would enter 08:00 then select AM for
example to start and then type 08:15 then select PM for a persons end
time.

This might be a stupid question, but how would I calculate this? Would
DateDiff take into account that this would be 12 hours and 15 minutes
or would it see it as only 15 minutes?

Would it be easier to just use military time 08:00 to 20:15?

I would also like the calculation value to show up on the form in a
field such as "TotalHours".

Thanks for any help to get pushed in the right direction.

Regardless of the format, a Date/Time field is stored as a double float count
of days and fractions of a day (times) since midnight, December 30, 1899. For
example, 8:00AM is stored as 0.3333333333333333333 and corresponds to
#12/30/1899 08:00:00#. The AM/PM is merely one way of depicting the time - you
can enter military time instead, just two ways to put in the exact same value.

You can use DateDiff() to calculate the time elapsed between two time points:
e.g. DateDiff("n", [Start Time], [End Time]) will calculate the minutes
elapsed. The result will be 15 if you use 8:00AM and 8:15AM, and 735 i you use
8:00AM and 8:15PM. You can divide that number by 60 if you want to see
fractional hours (0.25 and 8.25 respectively).

If you're using two controls, a textbox and an option group, you'll need VBA
code to add 12 hours when the user selects pm. I'd use the DateAdd function to
do so, or - maybe better - train the users to simply type the am or pm. If
need be use an Input Mask such as 00:00 LL to force entry of four digits and
two letters. I'd use that as a last resort, masks can be more annoying than
helpful at times!
 
Ad

Advertisements

A

Al Campagna

P-rat,
I don't understand what you're asking. I gave you examples as to how to
enter am times and pm times.
Format the time controls (ex. StartTime and StopTime) for...
hh:nn am/pm Then enter...
"8:00 a" to get 8:00 am
"8:15 p" to get 8:15 pm.
(don't enter the quotes... they signify a string the user is typing in)

Now... DateDiff("n", [Start Time], [End Time])
would yield 735 minutes. Divide by 60 to get the decimal value of 12.25
hrs.

I'd rather that users enter the correct time value, using the above
method... or military time, and do away with the AM/PM checkbox.
But... see John Vinson's response, if you plan to use that method. He
addresses that issue.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."




how would it work with the "8:15 a" scenario. not familiar. thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top