For two arrays (of different length) with datetime values, I want to flag those entries where the date (year, month, day) in both is the same while ignoring the time values. The issue is that the datetime type internally always also contains a time (even the constructor datetime(Y,M,D) will internally set the time to 00:00:00). Therefore a direct comparison of datetimes (dt1 == dt2) will give true only if the times are also the same.
E.g.:
arDt1 = datetime(2021,5,1:10,0,0,0); % 1. to 10. May, always at time 00:00:00
arDt2 = datetime(2021,5,1:2:10,12,0,0); % 1.,3.,5.,7.,9. May always at time 12:00:00
The desired logical array of flags for arDt1 would thus be
[ 1 0 1 0 1 0 1 0 1 0] % days in arDt1 which are also in arDt2, *never mind the time*
The real data extend across multiple months and years, so using the day-of-month number alone is not sufficient (even if it would be for the example above).
I can think of various work-arounds (converting datetime to string and parsing; using ymd() and then compare year, month, day "piecewise"; or forcing all times, at least temporarily, to be the same, e.g. 00:00:00), but it all gets a bit clumsy, esp. when arrays of different lengths are involved, which means ismember() has to be used instead of a direct one-to-one array comparison.
The problem of of processing only the date part of datetime values, regardless of the time part, should be a rather general one, but I can't find any examples or references. Can someone advise a more elegant/efficient way?