working with time

K

Karen

I'm trying to take two fields (timestart and timestop) and figure out the
time in hours (timeinhours).

So if timestart = 11:15 and timestop = 11:30, I want timeinhours to be .25.

The only thing I've come up with shows timeinhours as :15. Timeinhours is a
unbound textbox, in this case formatted as 'short time' and with a
datasource of
=[timestart]-[timestop]. (Also with the above formula and control
properties, 11:15 - 1:00 is 10:15?!?!?!)

Does any one have any ideas how I can do this?

Karen
 
K

Karen

I'm sorry, I'm still lost.

I understand that :15 is a quarter of an hour but I need the control
timeinhours to display '.25' not ':15'.

By 'basic time subtraction' do you mean 11:15 - 11:30? If I do
(timestart-timestop)/24 the result is -0.000434

with my apologies for being thick in the head about this,
Karen

Peter R. Fletcher said:
.25 hours is 15 minutes (0:15), so your math is right!

Date/Time fields would be better named "Datestamp" fields - they are
really intended to hold a value corresponding to such and such a time
on such and such a date. Internally, they are stored as special
floating point numbers of which the integer part represents the day
and the fractional part represents the time, as a fraction of a _day_.
If you want to display a time difference in hours, you need to divide
the result of your basic time subtraction by 24 and format it as a
regular floating point number with however many decimal places you
want to see.

Your second problem results from the "Short Time" format displaying
"negative time" without anything that distinguishes it from "positive
time". If you put in a time without specifying am or pm, it will be
assumed that you are using a 24 hour clock. 1:00 - 11:15 thus comes
out to a time value equivalent to _minus_ 10:15, which is meaningless,
and Access ignores the negative sign and displays the time value.

You can deal fairly easily with times that do not cross midnight if
you use the 24 hour clock to enter them and multiply differences byt
the appropriate number to get them in the units that you want. With
slightly more difficulty, you can deal in a similar way with times
that do cross midnight, provided that differences are guaranteed to be
less than 24 hours. Beyond that, life gets fairly fraught.


I'm trying to take two fields (timestart and timestop) and figure out the
time in hours (timeinhours).

So if timestart = 11:15 and timestop = 11:30, I want timeinhours to be ..25.

The only thing I've come up with shows timeinhours as :15. Timeinhours is a
unbound textbox, in this case formatted as 'short time' and with a
datasource of
=[timestart]-[timestop]. (Also with the above formula and control
properties, 11:15 - 1:00 is 10:15?!?!?!)

Does any one have any ideas how I can do this?

Karen


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
K

Karen

I used the following and it gives me the times. My times never go over
midnight. We are tracking the time on small job runs.

=(Hour([fldtimestop]-[fldtimestart])+((Minute([fldtimestop]-[fldtimestart])/
60)))

Thanks for all of your help.
 
J

John Vinson

I'm trying to take two fields (timestart and timestop) and figure out the
time in hours (timeinhours).

So if timestart = 11:15 and timestop = 11:30, I want timeinhours to be .25.

The only thing I've come up with shows timeinhours as :15. Timeinhours is a
unbound textbox, in this case formatted as 'short time' and with a
datasource of
=[timestart]-[timestop]. (Also with the above formula and control
properties, 11:15 - 1:00 is 10:15?!?!?!)

Does any one have any ideas how I can do this?

I'd suggest using the DateDiff function - it's designed to calculate
differences between two date/time values in any units from seconds to
years.

To get fractional hours, get the time difference in miNutes ("m" is
Months) and divide by 60:

DateDiff("n", [timestart], [timestop]) / 60
 

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