Clear Filters
Clear Filters

Datetimes don't seem to be recognised

2 views (last 30 days)
Can anyone explain to me why this isn't working? For some reason, the datetime t is not recognised as occurring between times.t1.start and times.t1.end, even though it DOES! It is recognised as occurring after t1.start, but not before t1.end.
isbetween() also does not work so I am guessing I have overlooked something simple...
t=gps.DateTime(ii) %reading same datetime from my table
%if vessel position time occurs during particular transect working on
if (t>=start)&&(t<last)
%append it to specific part of structure
disp('It works!')
disp('It does not work')
%Datetime from my table:
t =
11-Aug-2021 09:59:25
%Datetime datetime(2021,08,11,09,59,25)
t =
11-Aug-2021 09:59:25

Accepted Answer

Star Strider
Star Strider on 10 Nov 2021
I’m not certain what you’re doing and I can’t run the posted code. I’m also not certain what the actual problem is.
See if the isbetween function will do what you want with respect to the if block.
Louise Wilson
Louise Wilson on 10 Nov 2021
All good, it works perfectly :-) Thank you. The data I am working with is huge and a lot of time consuming processing has already been done so the fix up solution is preferrable by far!
Steven Lord
Steven Lord on 10 Nov 2021
If that doesn't work, perhaps the data in the file was more precise than you thought it was.
t1 = datetime(2021, 11, 10, 14, 25, 00)
t1 = datetime
10-Nov-2021 14:25:00
t2 = datetime(2021, 11, 10, 14, 25, 0.4)
t2 = datetime
10-Nov-2021 14:25:00
t1 >= t2 % correctly false even though they display the same
ans = logical

Sign in to comment.

More Answers (0)


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!