How to elegantly convert from DateObject to TimeObject?

The purpose is to extract time from the DateObject and manipulate only time components afterwards.

  • $\begingroup$ It seems that for the methods below to work, DateObject must contain the time. It is possible to have DateObject without the time, in which case error will be returned. A way around this is to call DateString[dateObject, {"Hour","Minute","Second", "Millisecond"}] $\endgroup$
    – Karolis
    Aug 28, 2015 at 16:41

2 Answers 2


TimeObject can take a DateObject so:

datetime = DateObject[]
time = TimeObject[datetime]

Since the FullForm of a DateObject looks like this:


we can use Cases:

now = DateObject[]
Cases[now, TimeObject[__]][[1]]

enter image description here

Or even simpler:

  • $\begingroup$ Not anymore: probably since v11.1, the full form is DateObject[{2019, 5, 21, 12, 55, 24.6968067}, "Instant", "Gregorian", 2.]. $\endgroup$ May 21, 2019 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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