datetime values appear to be equal but return not equal
Show older comments
I have two datetime variables that appear to be the same (even using format long), but matlab says they are not equal:
Any idea what's going on here? I discovered this because the setxor function told me these values were mutually exclusive.
K>> T1(1)
ans =
datetime
24-Aug-2020 18:00:01.730
K>> T2(2)
ans =
datetime
24-Aug-2020 18:00:01.730
K>> datenum(T1(1))
ans =
7.380277500200346e+05
K>> datenum(T2(2))
ans =
7.380277500200346e+05
K>> isequal(T2(2),T1(1))
ans =
logical
0
Accepted Answer
More Answers (1)
Steven Lord
on 1 Apr 2021
What does this show you?
seconds(T2(2)-T1(1))
That will likely be small enough to make no difference in how those datetime values are displayed but large enough to make them not return true for the equals calculation.
2 Comments
Dan Klisiewicz
on 1 Apr 2021
You forgot the seconds call.
T1 = datetime('now')
T2 = T1 + seconds(1e-4)
T2-T1
seconds(T2-T1)
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!