I get wrong logic while I compare two datetimes
Mostrar comentarios más antiguos
Hello
Thank you for paying attention to my question.
The format I introduced for the datetimes in my table is ' 'hh:mm:ss dd/MM/uuuu'
but I am wondering why I get the datetime as below. The year must be 2022 instead of 0022.
Besides, when I campare datetimes, the logic is not correct for instance the logic of D has to be 1 but zero is shown instead.
would you please guide me.
A = datetime
00:43:43 29/06/0022
B = datetime
03:26:53 07/01/0022
C = datetime
08:40:28 07/01/0022
D = isbetween (A,C,B)
D = logical
0
3 comentarios
Walter Roberson
el 31 de Ag. de 2022
caution, hh is 12 hour clock not 24 hour
Rik
el 1 de Sept. de 2022
@Arezoo Ghanbari flags are meant to attract the attention of admins. If you think an answer is good, please consider giving it an upvote (if you haven't done so already) and comment with a thank you.
Star Strider
el 2 de Sept. de 2022
Respuesta aceptada
Más respuestas (1)
Note that isbetween(t,tlower,tupper) is used to check the following logic: tlower <= t & t <= tupper.
See below for the code run, and an extra logic check.
TimeFormat = 'hh:mm:ss dd/MM/yyyy';
A = datetime("00:43:43 29/06/2022",'InputFormat',TimeFormat)
B = datetime("03:26:53 07/01/2022",'InputFormat',TimeFormat)
C = datetime("08:40:28 07/01/2022",'InputFormat',TimeFormat)
Note that isbetween(t,tlower,tupper) is used to check the following logic: tlower <= t & t <= tupper
D = isbetween(A,C,B)
Hence the above is correct... 29 june is not between the two times on 7 january.
D = isbetween(C,B,A)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!