time listing

G

Guest

I have a form that has 2 fields on it for time start and time end (not date).
A third field records the difference between the start and end time. If a
person records a time of 8:30am to 9:30am the third field shows .99 as the
difference. I need it to show 1 for one hour of time. The times will never
crossover midnight (if it did I think someone needs to get a life). The
times are typed in as military time but show on the main form as regular time
format. The code line that fills the 3 field with the difference is as
follows:

Me.txtWorkTimeAmount = 24 * (Me.txtProjectWorkEndTime -
Me.txtProjectWorkStartTime)

This line is in the end time after_update event.

How do I go about showing the 1 instead of .99?

Thanks ... John
 
J

John W. Vinson

I have a form that has 2 fields on it for time start and time end (not date).
A third field records the difference between the start and end time. If a
person records a time of 8:30am to 9:30am the third field shows .99 as the
difference. I need it to show 1 for one hour of time. The times will never
crossover midnight (if it did I think someone needs to get a life). The
times are typed in as military time but show on the main form as regular time
format. The code line that fills the 3 field with the difference is as
follows:

Me.txtWorkTimeAmount = 24 * (Me.txtProjectWorkEndTime -
Me.txtProjectWorkStartTime)

This line is in the end time after_update event.

How do I go about showing the 1 instead of .99?

Thanks ... John

What would you want to see if the entry was 8:30 to 9:45?

You may want to investigate the DateDiff() function, which does the
calculation in any units from seconds to years. For instance, you might want
to try

DateDiff("h",[txtProjectWorkStartTime],[txtProjectWorkEndTime])

for integer hours; or use "n" for miNutes ("m" is Months) and divide by 60 to
get one-minute granularity.

John W. Vinson [MVP]
 
G

Guest

Hi Mr Vinson. Sorry for not getting back to you sooner. The DateDiff() does
work, but it only returns back even hours. In your example of 8:30 to 9:45 I
would need to return 1.25 hrs. DateDiff() does not seem to do that. At
least it took care of the .99 hrs I was getting.
Any suggestions?
.... John


John W. Vinson said:
I have a form that has 2 fields on it for time start and time end (not date).
A third field records the difference between the start and end time. If a
person records a time of 8:30am to 9:30am the third field shows .99 as the
difference. I need it to show 1 for one hour of time. The times will never
crossover midnight (if it did I think someone needs to get a life). The
times are typed in as military time but show on the main form as regular time
format. The code line that fills the 3 field with the difference is as
follows:

Me.txtWorkTimeAmount = 24 * (Me.txtProjectWorkEndTime -
Me.txtProjectWorkStartTime)

This line is in the end time after_update event.

How do I go about showing the 1 instead of .99?

Thanks ... John

What would you want to see if the entry was 8:30 to 9:45?

You may want to investigate the DateDiff() function, which does the
calculation in any units from seconds to years. For instance, you might want
to try

DateDiff("h",[txtProjectWorkStartTime],[txtProjectWorkEndTime])

for integer hours; or use "n" for miNutes ("m" is Months) and divide by 60 to
get one-minute granularity.

John W. Vinson [MVP]
 
J

John W. Vinson

Hi Mr Vinson. Sorry for not getting back to you sooner. The DateDiff() does
work, but it only returns back even hours. In your example of 8:30 to 9:45 I
would need to return 1.25 hrs. DateDiff() does not seem to do that. At
least it took care of the .99 hrs I was getting.

Try

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

to calculate the difference in minutes and convert to fractional hours. Round
to any accuracy you like or leave unrounded (but it will give you numbers like
1.16666666).

John W. Vinson [MVP]
 
G

Guest

Thank you, Mr Vinson. It worked.
.... John



John W. Vinson said:
Hi Mr Vinson. Sorry for not getting back to you sooner. The DateDiff() does
work, but it only returns back even hours. In your example of 8:30 to 9:45 I
would need to return 1.25 hrs. DateDiff() does not seem to do that. At
least it took care of the .99 hrs I was getting.

Try

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

to calculate the difference in minutes and convert to fractional hours. Round
to any accuracy you like or leave unrounded (but it will give you numbers like
1.16666666).

John W. Vinson [MVP]
 

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