How to check whether datetime is within range
23 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Star Strider
2022 年 4 月 8 日
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!
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!