How to check whether datetime is within range
22 views (last 30 days)
Show older comments
This is the code:
>> C = strsplit('02.02.1957-13.02.1957','-')
C1=datetime(C{1},'InputFormat','dd.MM.yyyy')
C2=datetime(C{2},'InputFormat','dd.MM.yyyy')
C =
1×2 cell array
{'02.02.1957'} {'13.02.1957'}
C1 =
datetime
02-Feb-1957
C2 =
datetime
13-Feb-1957
Now, I would like to know, if e.g. '03.02.1957' is within '02.02.1957-13.02.1957'. Ist there a simple function for this? For 13.02.1957 the value should also be "true".
Thank you!
0 Comments
Accepted Answer
Star Strider
on 8 Apr 2022
There are several ways to do this, all using logical indexing. The easiest way is with the isbetween function.
C = strsplit('02.02.1957-13.02.1957','-');
C1=datetime(C{1},'InputFormat','dd.MM.yyyy');
C2=datetime(C{2},'InputFormat','dd.MM.yyyy');
Query = datetime('03.02.1957','InputFormat','dd.MM.yyyy');
TF = isbetween(Query, C1, C2)
So ‘Query’ is in the interval!
.
More Answers (0)
See Also
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!