Hi, I'm new to VB--I would like to know how to subtract between time periods i.e. In 8:35am Out 11:40am and I would have to do this for at least 5 different times in one day (Employee Time Sheet).
Any help would be greatly appreciated thanks,
JT
Printable View
Hi, I'm new to VB--I would like to know how to subtract between time periods i.e. In 8:35am Out 11:40am and I would have to do this for at least 5 different times in one day (Employee Time Sheet).
Any help would be greatly appreciated thanks,
JT
I would convert it all to minutes, do the subtraction, and then back to hours
The datediff function returns the difference between to dates in specified time intervals
difference = DateDiff(interval, date1, date2)
where interval can be:
Code:yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Be careful with datediff:
It will return 1 day, one hour or one minute between 1 second to midnight and one second after midnight.
If this period extends over 31st December - 1st January then datediff returns one year, although if you ask for the result in seconds the result is two seconds as expected.
It all depends on the size of the interval.
On a timesheet, asking for the result in hours, you may credit someone with one hour for two minutes work.
I would agree with dimava - calculate in minutes then convert it back.