Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

doing calculation with "time"

Status
Not open for further replies.

TVTPeggy

Programmer
Apr 27, 2004
10
US
is there a conversion process built into access (or can be coded in) that would allow the entry of time to be left in hours and minutes and calculate the difference on it. Example the difference between 2:15 and 1:45 is 30 minutes. Of course 215 minus 145 is 70. Short of converting time to decca (2.25 minus 1.75) i don't know how to arrive at the correct result. Someone has got to have conquered this somewhere...

Thanks,
Peggy
 
Something like this ?
t1 = "2:15": t2 = "1:45"
MsgBox Format(CDate(t1 & ":00") - CDate(t2 & ":00"), "h:nn")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I had something very similar a while back and I just used the following formula

Time = ((Time1 - Time2)/.041666667)*60

So ((2:15-1:45)/.041666667)*60 = 30

If you eliminate the multiplication by 60 you would get the portion of the hour (.5).

Hope This Helps

 
I like the overall concept from PHV, but it doesn't need to be quite that 'elaborate'


Code:
t1 = "2:15"
t2 = "1:45"
? Format(CDate(t1) - CDate(t2), "h:nn") 
0:30




MichaelRed
mlred@verizon.net

 
Michael

Your solution is very clean. I much prefer that to my solution.

I needed mine to perform wage calculations, so it needed to be in a decimal format.
 
Thank you all for all the answers. I haven't had time to test them (programming is secondary to all my other duties). The search for similar thread function wasn't working when I posted this yesterday but since then have found other answers so I am confident I will make something work. Thanks again. You are better than an the expensive courses I took for access.

TVT-Peggy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top