How to Compare datetimes with milisecs?
Show older comments
Hi, when i compare the i-value from each table it says they are not the same becauase one has milisecs and the other has not, how to delete the mili secs so when i do
u1200lab(1,1)==u1300processo(1,1)
it gives me a positive logical answer?
Because now it says it is not true
Accepted Answer
More Answers (2)
Are Mjaavatten
on 7 Feb 2018
s = 30; % The accuracy you desire (in seconds)
close_enough = abs(u1200lab(1,1)-u1300processo(1,1)) < 1/24/3600*s
1 Comment
Tiago Dias
on 8 Feb 2018
Peter Perkins
on 7 Feb 2018
This has nothing to do with milliseconds, at least not if what you posted is what you are actually doing.
I don't know what you are seeing, but the two mat files you've attached each contain an 8x1 table, each of whose sole variable is an 8x1 datetime. These tables may be a step along a longer journey, but in general, there's no point in creating a table with one variable.
In any case, what I see is
>> u1200lab(1,1)==u1300processo(1,1)
Undefined operator '==' for input arguments of type 'table'.
and that's because you are wanting to compare the datetime values in the table but in fact you are trying to compare two 1x1 tables and there's no comparison operator for tables because they are containers. What you need to do is compare the datetime values. Here's one way:
>> u1200lab.DataColheita(1) == u1300processo.Data(1)
ans =
logical
1
3 Comments
Tiago Dias
on 8 Feb 2018
Walter Roberson
on 8 Feb 2018
In u1200lab.DataColheita(1) the .DataColheita tells it which column of the table to look in. The (1) is then the row number of that column.
Tiago Dias
on 8 Feb 2018
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!