5
$\begingroup$

(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?

$\endgroup$
5
$\begingroup$

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

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

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.