I get wrong logic while I compare two datetimes
显示 更早的评论
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 个评论
Walter Roberson
2022-8-31
caution, hh is 12 hour clock not 24 hour
Rik
2022-9-1
@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.
采纳的回答
更多回答(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)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!