7
$\begingroup$

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!

$\endgroup$
13
$\begingroup$

Another, shorter way is

Append[d, t]

Mathematica graphics

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.} *)
$\endgroup$
4
$\begingroup$

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).

$\endgroup$
3
$\begingroup$

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

Well...

d~d[[0]]~t

...seems to work.

$\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.