Results 1 to 2 of 2
Thread: Elapsed Time Calculations
2010-04-09, 17:26 #1
- Join Date
- Mar 2004
- White Oak, Pennsylvania, USA
- Thanked 0 Times in 0 Posts
I wrote a time sheet program that uses a form on which the users enter the starting time of an activity and an ending time of the activity.
I assumed the users would understand that PM times were 12 hours + the actual time (enter 14:00 for 02:00 PM) but they can't seem to get that right.
I'm changed the form so that they and enter an A or a P to designate the AM or PM time frame of their entry.
My problem is I am unable now to do the calculations correctly. I try adding 12 to the PM time of 2:00 PM (ex. txtET+12 ) but Access doesn't want to make that 14:00 but seems to add 12 days?
I have the times formatted as ShortDate. I tried removing the formatting but got a type mismatch error. Is there a conversion function or something of the like that will change 02:00 to 14:00 if it is designated as a PM time and then allow me to do the elapsed calculations correctly?
Can you help me with this, please?
2010-04-09, 18:14 #2
- Join Date
- Aug 2001
- Evergreen, CO, USA
- Thanked 64 Times in 63 Posts
There are a number of posts about Time calculations in this forum that are related to this subject. The key thing to remember is that Access stores times in date and time fields as the decimal part of a day. Thus 6:00 AM is stored as 0.25 plus whatever day it is, 12:00 PM is stored as 0.5 and so on. So as long as you let Access do it's thing, you can simply compute the difference between two times using basic arithmetic, and then multiply that by 24 to get the hours and fraction hours. If you need it to be done in hours and minutes it gets a bit more complicated - you have to multiply the fraction of hours by 60, but the principle is the same.Wendell