Modern software should not do this, something annoying that can be improved

2 visualizaciones (últimos 30 días)
Hey Matworks,
Im sure there is an expert explanation to this but that just DONT MATTER!
A modern software should NOT behave like this because it takes peoples time away from more important things! Still love your app though.
Even if I were to check matches between MM/dd/yyyy and MM/dd/yyyy HH:mm:ss and if the first part match it should match regardless hours and minutes and seconds, but to be be even more defective check below where MM/dd/yyyy dont match with MM/dd/yyyyy!!! Yes sure, there are hidden craps behind, but who cares! You should!
DATA.(name).Date(1:2,:)
ans =
2×1 datetime array
12/27/2024
12/26/2024
K>> Date
Date =
datetime
12/27/2024
K>> idx_ED=find(DATA.(name).Date==Date)
idx_ED =
0×1 empty double column vector
K>> disp(DATA.(name).Date(1).Format);
disp(DATA.(name).Date(1).TimeZone);
disp(Date.Format);
disp(Date.TimeZone);
MM/dd/yyyy
MM/dd/yyyy
K>> DATA.(name).Date = dateshift(DATA.(name).Date, 'start', 'day');
Date = dateshift(Date, 'start', 'day');
idx_ED = find(DATA.(name).Date == Date)
idx_ED =
1.00
  2 comentarios
Walter Roberson
Walter Roberson el 28 de Dic. de 2024
Do I understand correctly that your belief is that the result of comparisons on datetime objects should depend on their Format ? Especially that if the format is MM/dd/yyyy then only month, day, and year should be compared?
If so what should be the results of comparing datetime objects that have different Format ? Should the missing fields be silently set to 0, or should it be an error?
What about if the datetime objects have different timezones, should the timezone be ignored if it is not part of the Format of the object? Should 12/26/2024 23:11 CST (Central Standard Time) with display set to MM/dd/yyyy compare the same or different to 12/27/2024 00:11 EST (Eastern Standard Time) if the Display is set to MM/dd/yyyy ?
Catalytic
Catalytic el 28 de Dic. de 2024
Even if I were to check matches between MM/dd/yyyy and MM/dd/yyyy HH:mm:ss and if the first part match it should match regardless hours and minutes and seconds
That sounds very doubtful to me. What if you want to compute a duration by subtracting two datetimes -
dur = datetime( '12/27/2024 15:30:45' ) - datetime('12/27/2024')
dur = duration
15:30:45
By your reasoning, the operation above would give zero. Mathworks, if you're listening, I do not want that.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 28 de Dic. de 2024
There are ways to deal with inequalities in datetime arrays. If you want to compare only the days (not considering the times), one option is sto use the datevec function and the other is to use the day funciton with the 'dayofyear' option --
DatesTimes = datetime(2024,12,27)+days([-366 0 0 1]).' + days(rand(4,1))
DatesTimes = 4x1 datetime array
27-Dec-2023 17:22:23 27-Dec-2024 09:12:45 27-Dec-2024 04:41:18 28-Dec-2024 04:22:35
dv = datevec(DatesTimes)
dv = 4×6
1.0e+03 * 2.0230 0.0120 0.0270 0.0170 0.0220 0.0232 2.0240 0.0120 0.0270 0.0090 0.0120 0.0460 2.0240 0.0120 0.0270 0.0040 0.0410 0.0189 2.0240 0.0120 0.0280 0.0040 0.0220 0.0359
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Check_1 = dv(1,1:3) == dv(2,1:3)
Check_1 = 1x3 logical array
0 1 1
Check_1 = all(dv(1,1:3) == dv(2,1:3),2)
Check_1 = logical
0
Check_2 = dv(2,1:3) == dv(3,1:3)
Check_2 = 1x3 logical array
1 1 1
Check_2 = all(dv(2,1:3) == dv(3,1:3),2)
Check_2 = logical
1
Check_3 = day(DatesTimes(1),'dayofyear') == day(DatesTimes(2),'dayofyear')
Check_3 = logical
0
Check_4 = day(DatesTimes(1),'dayofyear') == day(DatesTimes(3),'dayofyear')
Check_4 = logical
0
Check_5 = day(DatesTimes(1),'dayofyear') == day(DatesTimes(4),'dayofyear')
Check_5 = logical
0
Check_6 = day(DatesTimes(2),'dayofyear') == day(DatesTimes(3),'dayofyear')
Check_6 = logical
1
Check_7 = day(DatesTimes(2),'dayofyear') == day(DatesTimes(4),'dayofyear')
Check_7 = logical
0
There are ways to compare them, however those are not obvious. It would be nice if the ismembertol function worked with datetime arrays (perhaps something to consider in that, or a similarly-named function for datetime arrays), however it does not at present. You can certainly create your own similar functin using the approaches I used here, or others.
.

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!

Translated by