Skip to content

DateObject

Represents a calendar date.

$ wo 'DateObject[{2026, 4, 15}][[1]]'
{2026, 4, 15}

An ISO date string is parsed into a date with the implied granularity.

$ wo 'DateObject["2024-03-15"]'
DateObject[{2024, 3, 15}, Day]
$ wo 'DateObject["2024-03"]'
DateObject[{2024, 3}, Month]

A granularity keeps only the components it names, so a "Month" object stands for the whole month:

$ wo 'DateObject[{2024, 2, 29, 13, 5, 7}, "Month"]'
DateObject[{2024, 2}, Month]
$ wo 'DateWithinQ[DateObject[{2024, 1, 1}, "Year"], DateObject[{2024, 5, 1}]]'
True
$ wo 'DateObject[{2024, 2, 29}]["Granularity"]'
Day

A date is itself a date specification, so a second DateObject re-tags it — DateObject[Now, "Hour"] is the hour Now falls in, the key a package caching once an hour keys its entries on:

$ wo 'DateObject[DateObject[{2026, 9, 8, 10, 14, 50.5}], "Hour"]'
DateObject[{2026, 9, 8, 10}, Hour, Gregorian, 0.]

"Second" drops the fraction that "Instant" keeps:

$ wo 'DateObject[DateObject[{2026, 9, 8, 10, 14, 50.5}], "Second"]'
DateObject[{2026, 9, 8, 10, 14, 50}, Second, Gregorian, 0.]

Refining a coarse date pads the missing components; a date that carries no offset of its own gets None:

$ wo 'DateObject[DateObject[{2026, 9}], "Hour"]'
DateObject[{2026, 9, 1, 0}, Hour, Gregorian, None]