5

(This question was inspired by my off-target answer to the question How to get the size of a DateObject?). The answer was not obvious to me, so I think a question/answer for this would be useful)

How can I programmatically determine properties like the time zone, calendar type and granularity of a DateObject without examining it's full form? For example:

date = CurrentDate[Now, "Week"];
date //InputForm

DateObject[{2018, 2, 26}, "Week", "Gregorian", -8.]

Is there an accessor function that will return "Week", "Gregorian" and -8?

Carl Woll
  • 130,679
  • 6
  • 243
  • 355

1 Answers1

5

You can use the accessor function DateValue to do this. For example:

DateValue[date, {"Granularity", "TimeZone", "CalendarType"}]

{"Week", -8., "Gregorian"}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355