Natasha
11-05-2001, 05:35 AM
Hello,
I am using the datediff function to find the number of hours between two dates.
However, if possible I'd like to calculate the minutes as well.
i.e my code is TxtBox3.Value = DateDiff("h", TxtBox1, TxtBox2, VbMonday)
Obviously, I know the problem is due to the "h", and I've looked at the help to find out "n" is minutes, but I'm not sure what the exact format to use is.
Thank you for any help you can offer.
Natasha.
Pat Hartman
11-05-2001, 07:01 AM
Use the DateDiff() function to calculated the difference in minutes. Then divide the minutes by 60 to get hours and use the Mod operator to get the remaining minutes.
TotMinutes = DateDiff("m", TxtBox1, TxtBox2, VbMonday)
TxtBoxHours = TotMinutes \ 60 'return hours as integer
TxtBoxMinutes = TotMinutes Mod 60 'return remainder
Natasha
11-05-2001, 07:59 AM
Hi Pat,
Many Thanks for your response.
I have done as you suggest, and it almost works.
What now happens is as follows :
I have date/time (all in one box), then I have an hours between box and a minutes between box.
Lets say box 1 is 01/01/01 09:00
and also box 2 is 01/01/01 11:30
the difference is correctly calculated as 150 minutes, however, the hours difference box rounds up to 3 hours (instead of 2)
Is there any way I can get round this ?
Thank you in advance.
Natasha.
R. Hicks
11-05-2001, 09:09 AM
If you are not declaring "TxtBoxHours" as an Integer in your code then you need to do this or use:
TxtBoxHours = Int(TotMinutes \ 60) 'return hours as integer
Pat Hartman
11-05-2001, 01:09 PM
The backslash operator "\" is supposed to truncate and should always result in an integer. Did you perhaps type a forward slash "/" instead?
R. Hicks
11-05-2001, 01:24 PM
LOL ... i did not even notice the direction of the slash .... sorry Pat.
RDH