I get wrong logic while I compare two datetimes
Show older comments
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 Comments
Walter Roberson
on 31 Aug 2022
caution, hh is 12 hour clock not 24 hour
Rik
on 1 Sep 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.
Accepted Answer
More Answers (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)
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!