Subtracting time

K

Katrina

I have the fields End Time, start time and hours worked.

I would like access to subtract start time from end time
to give me hours worked after inputting the end time.

It is not working out. I want a number field. For
example, if I start @ 1:00 PM and end at 2:15 PM I want
the hours worked to say 1.25.

I plan on using this in the After Update method. ANy
suggestions?
 
J

John Vinson

I have the fields End Time, start time and hours worked.

I would like access to subtract start time from end time
to give me hours worked after inputting the end time.

It is not working out. I want a number field. For
example, if I start @ 1:00 PM and end at 2:15 PM I want
the hours worked to say 1.25.

I plan on using this in the After Update method. ANy
suggestions?

Use the DateDiff() function. Despite the name, it's functional for
times as well. If you want fractional hours, calculate the difference
in miNutes and divide by sixty:

Round(DateDiff("n", [StartTime], [EndTime]) / 60., 2)
 
K

Katrina

FOr some reason, this command is only giving me whole
housrs.... I copied it exactly how you have it...

Any suggestions?
-----Original Message-----
I have the fields End Time, start time and hours worked.

I would like access to subtract start time from end time
to give me hours worked after inputting the end time.

It is not working out. I want a number field. For
example, if I start @ 1:00 PM and end at 2:15 PM I want
the hours worked to say 1.25.

I plan on using this in the After Update method. ANy
suggestions?

Use the DateDiff() function. Despite the name, it's functional for
times as well. If you want fractional hours, calculate the difference
in miNutes and divide by sixty:

Round(DateDiff("n", [StartTime], [EndTime]) / 60., 2)



.
 
G

Guest

FOr some reason, this command is only giving me whole
housrs.... I copied it exactly how you have it...

Any suggestions?

-----Original Message-----
HrsWorked = DateDiff("n", [StartTime], [EndTime]) / 60


--
Ken Snell
<MS ACCESS MVP>

I have the fields End Time, start time and hours worked.

I would like access to subtract start time from end time
to give me hours worked after inputting the end time.

It is not working out. I want a number field. For
example, if I start @ 1:00 PM and end at 2:15 PM I want
the hours worked to say 1.25.

I plan on using this in the After Update method. ANy
suggestions?


.
 
A

Alex Dybenko

check what DateDiff("n", [StartTime], [EndTime]) returns in your case
should be number of minutes between 2 times

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com


Katrina said:
FOr some reason, this command is only giving me whole
housrs.... I copied it exactly how you have it...

Any suggestions?
-----Original Message-----
I have the fields End Time, start time and hours worked.

I would like access to subtract start time from end time
to give me hours worked after inputting the end time.

It is not working out. I want a number field. For
example, if I start @ 1:00 PM and end at 2:15 PM I want
the hours worked to say 1.25.

I plan on using this in the After Update method. ANy
suggestions?

Use the DateDiff() function. Despite the name, it's functional for
times as well. If you want fractional hours, calculate the difference
in miNutes and divide by sixty:

Round(DateDiff("n", [StartTime], [EndTime]) / 60., 2)



.
 
A

Allen Browne

Ken's formula is spot on.

For further info on how to work with elapsed time, see:
http://allenbrowne.com/casu-13.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

FOr some reason, this command is only giving me whole
housrs.... I copied it exactly how you have it...

Any suggestions?

-----Original Message-----
HrsWorked = DateDiff("n", [StartTime], [EndTime]) / 60


--
Ken Snell
<MS ACCESS MVP>

I have the fields End Time, start time and hours worked.

I would like access to subtract start time from end time
to give me hours worked after inputting the end time.

It is not working out. I want a number field. For
example, if I start @ 1:00 PM and end at 2:15 PM I want
the hours worked to say 1.25.

I plan on using this in the After Update method. ANy
suggestions?
 
J

John Vinson

FOr some reason, this command is only giving me whole
housrs.... I copied it exactly how you have it...

What's the context? Where are you using the expression?

If you're setting the value of an Integer or Long Integer field to the
expression, you'll get this effect: Integers, by definition, are whole
numbers.
 

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