# How to combine Date and Time objects into DateTime object?

Considering a DateObject d and TimeObject t:

In[1]:= t = TimeObject[{14, 1, 45.}]
In[2]:= d = DateObject[{2012, 06, 11}]


How can I achieve this result:

In[3]:= dt = DateObject[{2012, 06, 11, 14, 1, 45.}]


Thanks!

Another, shorter way is

Append[d, t]


From the docs,

DateObject[date,time] represents the specified date list and TimeObject time.

If you need the list you mention in the question, just convert the DateObject using DateList:

DateList@Append[d, t]
(* {2012, 6, 11, 14, 1, 45.} *)


A little late to the party here but this also works:

In[28]:= DateObject[d, t]


as Szabolcs noted, the documentation references this, but doesn't give an explicit example(which I will make sure gets added).

Strip off their heads. replace them with List and then Flatten them:

dt=DateObject@@(List @@@ {d, t} // Flatten)


DateObject[{2012, 6, 11, 14, 1, 45.}]

Or ....

dt=DateObject @@ Join @@ {d[[1]], t[[1]]}

• Why is the result no quantity/object, but only text? – SuTron Jun 17 '15 at 11:06
• My bad, it's early for me ;) – image_doctor Jun 17 '15 at 11:09
• Why not Join[] the lists instead? :) – J. M. will be back soon Jun 17 '15 at 11:21
• See recent update :) – image_doctor Jun 17 '15 at 11:22
• Well, I had DateObject @@ Join[d[[1]], t[[1]]], myself… :) – J. M. will be back soon Jun 17 '15 at 11:24

Well...

d~d[[0]]~t


...seems to work.