Subtract integer from time duration (1 Viewer)

Suppose you have an event venue. Each event has a Beginning Date, a Beginning Time, an Ending Date and Ending Time. I have had success with the following formula used in a textbox to calculate the hours between dates and times:
=DateDiff("n",EventBeginDate & " " & EventBeginTime,EventEndDate & " " & EventEndTime)/60
Example 1:
1713715173469.png

Example 2:
1713715289575.png
 
Code:
EventBeginDate & " " & EventBeginTime
Real?
I would expect one to add numbers.
 
Code:
EventBeginDate & " " & EventBeginTime
Real?
I would expect one to add numbers.
Not with DateDiff. ACCESS reads the EventBeginDate & " " & EventBeginTime as a General Date which includes both date and time components. It's the only way I know to calculate hours between different dates and times when the dates span more than 1 day. I used Short Dates and Medium Times. ACCESS will still calculate it properly using DateDiff. Users can input their dates and times separately.
 
Last edited:
Code:
DateDiff("n", EventBeginDate + EventBeginTime, EventEndDate + EventEndTime) / 60
DateTime values are internally numbers, and numbers can be processed mathematically directly, i.e. added.

Code:
EventBeginDate & " " & EventBeginTime
Composing with & creates a string.
DateDiff requires Variant (Date) as arguments.
If the string is accepted, an additional conversion step must be carried out internally, which means additional work.

But for me it's a stylistic problem. I calculate mathematically with numbers and do string processing with texts. Swimming between worlds does not give the impression of clarity, even if VBA allows a lot through internal processes.
 

Users who are viewing this thread

Back
Top Bottom