I got my data in 24 Hrs (Number Field) like 800 Hrs, 1400 hrs, 1432
Hrs. Anyone know how do I convert the above to time field, hh:nn, so I
can do a calculation to get the duration. I am aware that if the
field are all in time field, we can use the Elapsed Time function to
get the intervals.
VBA and Jet Date-Time fields store their values in units of Days: so you
can convert 0800 hrs = 8/24 days = 0.3333333
Since you seem to have packed a string value (yes, if 0845 means 08:45,
then it is a string value, not a number) then you have to do some
slicing:
dwMinutes = 60 * (dwTime div 100) + (dwTime mod 100)
dtDate = dwMinutes / 60! / 24!
I am not clear what use this will be, however, since VBA does not display
duration of more than 24 hours nicely at all: it'll try to give you a
date value somewhere in the middle of January 1900! If you really want to
use date-and-time maths, you are probably better off using a proper data
type. Consider:-
One Integer (or Long) field containing a suitable unit, say hours or
minutes. This makes validation easy, and maths trivial: but the user
interface takes some doing, since nobody wants to work out 8 hours in
minutes in their head every time.
Two integer fields, for hours and minutes: easy to validate, easy for
the user, but a bit more work when you do the maths.
A custom control. Since this question comes up here with regularity,
someone might have seen the value of developing an ActiveX control that
would take all the UI work out of solution 1. My C++ skills are nowhere
near that, but other people's are. Such a pity the CCRP project
disappeared, because it would have been a cinch for them. chiz chiz.
Hope that helps
Tim F