How to check whether datetime is within range
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
A.
el 8 de Abr. de 2022
Comentada: Star Strider
el 8 de Abr. de 2022
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 comentarios
Respuesta aceptada
Star Strider
el 8 de Abr. de 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!
.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!