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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access format for time/minutes in VBA code?

Status
Not open for further replies.

misssoysauce

Technical User
Dec 21, 2004
12
GB
I am creating a program for work that essentially calculates various charges and displays them on a form.

A couple charges are time-performance based. e.g. As a rental company, we agree to deliver the goods within 3.5 hours. If our delivery time exceeds that, then it qualifies as a late charge and may be subject to partial refunding. So, as below:

Function LateToSite(interval)

If interval > 3:30 Then
etc etc

But VBA does not accept this format. What is the proper format?

In another calculation I will have to subtract 60 minutes from the interval. I am puzzled on the formatting for this as well.

Any help would be greatly appreciated, I can't seem to find anything in Access Help or on the net about it.

 
MS products almost exclusively hold dates and times as NUMBERS which are FORMATTED to look like a date / time

All dates are calculated from 1/1/1900 and 1 day = 1 so today is actually 38342 (or 38342 days since 1/1/1900)

You can test this by entering 38342 in a cell in excel and then applying a date format to it.

In terms of times then, if 1 day = 1 then 1 hour must logically = 1/24,
1 minute = 1 / (24*60) and
1 second = 1 / (24*60*60)

Therefore, 3 1/2 hours can be expressed as 3.5*(1/24) so

Code:
If Interval > (3.5*(1/24)) then 
'...

should therefore do what you require. You should be able to work out the 60 mins subtraction from this.

If, after all that, you want to see the date / time as a true date / time, look into the FORMAT function within VBA

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top