I have a DateObject
with lots of granularity and additional specifications, such as the following e.g.:
dateFull =
DateObject[
List[2022, 7, 18, 14, 0, 0],
"Instant", "Gregorian", 0, "SmearedUTC",
List["DateTime", ":", "Millisecond"]
]
I would like to find a function f
such that f[dateFull]
returns DateObject[List[2022, 7, 18], "Day"]
. This makes comparing dates easier as I can use functions such as Complement
, DeleteDuplicates
etc. when I am only concerned with the "Day"
granularity.
In v13 I used to do this with DateObject[dateFull, "Day"]
(see also DateObject granularity conversion), but in v13.1 it now returns the CalendarType ("Gregorian") as well i.e.: DateObject[List[2022, 7, 18], "Day", "Gregorian", 0]
.
Doing something like f = DateObject[DateString[#, {"ISODate"}], "Day"]&
would work, but it feels ugly/hacky as it seems to imply that I would be better off working with Strings instead of DateObjects. (Indeed, given the ever evolving output of DateObject
that may well be the case: if memory serves, DateObject[x, "Day"]
behaviour was also different in v12. It seems like Wolfram is not quite happy with their dates behaviour.)
"Gregorian", 0
bit breaking any code? You can do something likeDateObject[dateFull, "Day"][[;; 2]]
which works in v12 through 13.1 from what I can tell $\endgroup$