How to check whether datetime is within range

23 ビュー (過去 30 日間)
A.
A. 2022 年 4 月 8 日
コメント済み: Star Strider 2022 年 4 月 8 日
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!

採用された回答

Star Strider
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)
TF = logical
1
So ‘Query’ is in the interval!
.
  2 件のコメント
A.
A. 2022 年 4 月 8 日
Thank you very much!
Star Strider
Star Strider 2022 年 4 月 8 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by