Having a hardtime with time

B

bob

Hi there again
Here is a the issue Im not that much of a expert with access ( in the
Expression area) I have a start time and finish time formatted like this
12:00:00 i have tried several different ways to (expressions ) to get it to
subtract the two times and it will sometimes but when i put in a time such as
16:09:15 and it changes that to 04:09:15 PM and the other time is 05:25:51
and that stays that way but the total field shows 1:16:36pm in reading the
other posting is it possible that I need to create to more fields that are
startdate and finishdate and put them in the expression like this
DateDiff("n"([startdate],[finishdate],[Starttime],[Finishtime])
or something like that. and can I in the table use the Date/Time

or am I going about this the wrong way

one last thing is it easier to write this is the expression box or i visual
basic program

thank you for the help
bob
 
R

Rick Brandt

bob said:
Hi there again
Here is a the issue Im not that much of a expert with access ( in the
Expression area) I have a start time and finish time formatted like
this 12:00:00 i have tried several different ways to (expressions )
to get it to subtract the two times and it will sometimes but when i
put in a time such as 16:09:15 and it changes that to 04:09:15 PM and
the other time is 05:25:51 and that stays that way but the total
field shows 1:16:36pm in reading the other posting is it possible
that I need to create to more fields that are startdate and
finishdate and put them in the expression like this
DateDiff("n"([startdate],[finishdate],[Starttime],[Finishtime])
or something like that. and can I in the table use the Date/Time

or am I going about this the wrong way

one last thing is it easier to write this is the expression box or i
visual basic program

thank you for the help
bob

Use one field for StartTime that contains the date and time. Use one field
for EndTime that contains both date and time. Use DateDiff on those two
fields.
 
C

Chris O''''Neill

bob said:
Hi there again
Here is a the issue...

You *are* having your challenges with this, aren't you Bob? (Grin!)

Just to expand on the anwer Rick gave you (which, by the way, is absolutely
correct), the reason you need both the date and time is that the time alone
does not define a specific point in time. For instance, having a start time
of 16:09:15 (or 04:09:15 PM if you will) and an end time of 05:25:51 doesn't
tell me anything. Is the start time today, yesterday, tomorrow or a week
from now? The same thing holds true for the end time.

You can use DateDiff() with just dates alone so long as you're not dealing
with hours minutes and seconds. However, you will never be successful using
DateDiff() to deal with time values (hours, minutes and seconds) if you don't
include a date. That's why in my previous response to you I concancated the
date and time together.
one last thing is it easier to write this is the expression box or i visual
basic program

As for which is "easier" to use to write a piece of code, the expression
builder or a VB subroutine or function, it really depends on what you're
doing. I find the expression builder best for easy things that can be done
in one line without alot of bracketing. However, if it's going to take a
fair amount of coding to do what I want, I find a VB subroutine or function
better.

Another thing to consider is whether the code you're writing is only needed
in one place in your application, or do you need it in several places. If
it's only needed once, then maybe the expression builder is better. But, if
it's going to be used throughout your application, it would be better to
create a subroutine or function in a module and then call it as needed.
Otherwise, you end up putting the same code all over the place.

I really *do* hope you get your time thing all figured out. It's been a bit
painful watching you struggle from the sidelines. (Grin!) I also hope my
code examples and general advice have been helpful. Frankly, I've not
received much feedback from you so I'm not sure if I'm helping or confusing
you further.

Kindest regards, and good luck with your coding...

Regards, Chris
 
C

Chris O''''Neill

Btw, I was wandering around researching another subject, and came across this
site that might be of interest to you:

http://www.accessmvp.com/djsteele/Diff2Dates.html

It's a custom function that you would call from your application (various
alternatives). To get the interval between to dates/times (yes you need the
date as well as the time) in hours/minutes/seconds, you do this:

Some_Variable_Or_Control = Diff2Dates("hns", #01/25/2002 01:23:01#,
#01/26/2002 20:10:34#)

The output will look like this: 42 hours 47 minutes 33 seconds

Not sure if it's useful, but thought you might want to have a look.

Regards, Chris
 

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