Time question

G

Guest

I have a field in a form, called "travel time" that is calculating the
difference between 2 other fields: "start time" and "end time". I am using
the date diff function as : datediff("n", [start time], [end time])
The result is a whole number. I would like to display the result as: h:mm
How can this be done?
Thank you,
 
J

Jeff Boyce

You'll need to "parse" your total number of minutes into hours and minutes.

Divide by 60 to get hours, add a ":", then take the remainder (you can use
the MOD function) to get minutes.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

Guest

How would I add that, and how would the formula be written?

Jeff Boyce said:
You'll need to "parse" your total number of minutes into hours and minutes.

Divide by 60 to get hours, add a ":", then take the remainder (you can use
the MOD function) to get minutes.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Iago said:
I have a field in a form, called "travel time" that is calculating the
difference between 2 other fields: "start time" and "end time". I am using
the date diff function as : datediff("n", [start time], [end time])
The result is a whole number. I would like to display the result as: h:mm
How can this be done?
Thank you,
 
G

Guest

x= DateDiff("n", StartTime, EndTime)
Me.txtTravelTime = format(x\60,"00:") & format(x mod 60, "00")

Notice the \ as the operator. It returns only the integer of the division
which is what you want in this case.

--
Dave Hargis, Microsoft Access MVP


Iago said:
How would I add that, and how would the formula be written?

Jeff Boyce said:
You'll need to "parse" your total number of minutes into hours and minutes.

Divide by 60 to get hours, add a ":", then take the remainder (you can use
the MOD function) to get minutes.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Iago said:
I have a field in a form, called "travel time" that is calculating the
difference between 2 other fields: "start time" and "end time". I am using
the date diff function as : datediff("n", [start time], [end time])
The result is a whole number. I would like to display the result as: h:mm
How can this be done?
Thank you,
 

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