Question

I have really strange behavior for one sql query in access databese. I'm trying to check if some time period is free in calendar, so I'm checking if there is any item between two specific date times. (vrijeme

SELECT eventDate, startTIme, startTIme+ duration, duration
FROM tblTermins
WHERE 
AND eventDate = #2014-03-30# 
AND (
(startTIme <= #11:00:00# AND (startTIme  + duration) >= #11:15:00#) 
OR (startTIme <= #11:00:00# AND (startTIme + duration) > #11:00:00#) 
OR (startTIme < #11:15:00# AND (startTIme + duration) >= #11:15:00#) 
OR (startTIme >= #11:00:00# AND (startTIme + duration) <= #11:15:00#)
) 

I get:

eventDate   startTIme    startTIme  + duration  duration
30.3.2014.  10:45:00     11:00:00               0:15:00 

Strange thing is that I shouldnt get that row at all because it doesnt fulfill the criteria. I checked for period between 11:00 and 11:15 and I got row with period 10:45 - 11:00. If I change OR (startTIme <= #11:00:00# AND (startTIme + duration) > #11:00:00#) into OR (startTIme <= #11:00:00# AND (startTIme + duration) > #11:00:01#), adding 1 second then problem is solved but first query should work as well

Was it helpful?

Solution

I did some testing with subtracting time partition of date/time types.

eventDate    startTime    duration
---------    ---------    --------
2014-03-30   10:45:00     00:15:00
...          ...          ...


SELECT eventDate, startTIme, duration, startTIme+duration AS endTime,
       CDbl(startTIme+duration) AS endTimeValue,
       CDbl(#11:00:00#) as elevenClockValue, 
       CDbl(startTIme+duration - #11:00:00#) As calculationDifference
FROM tblTermins 
WHERE 
[startTime]+[duration] >#11:00:00#


eventDate   startTIme   duration    endTime    endTimeValue    elevenClockValue    calculationDifference
---------   ---------   --------    -------    ------------    ----------------    ---------------------
30.03.2014  10:45:00    0:15:00     11:00:00   0,4583333333333 0,45833333333333    5,55111512312578E-17

After mathematical operations adding/deducting with time values and converting to numeric value we get small partition that makes difference from expected time.

So we could round numeric value or add 1 second if it doesnt conflict with application data and logic.

Even this query will return some difference

SELECT Cdbl(#10:45:00# + #00:15:00# - #11:00:00#) FROM tblTermins

Result
--------------------
5,55111512312578E-17

In additional testing I found that in most case I'll get correct value as result of subtraction or adding time values.

For example:

SELECT Cdbl(#10:35:00# + #00:25:00# - #11:00:00#) FROM tblTermins

Result
--------------------
0

It looks like it exist small bug in some cases of time callculation in Access.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top