6
$\begingroup$

I have problems with removing time and time zone information from a date object. I found the same question here already, but my starting position is slightly different. My date objects are imported from excel and look like

DateObject[{2008, 7, 3}, TimeObject[{0, 0, 0.}, TimeZone -> 2.], TimeZone -> 2.]

What I need is DateObject[{2008, 7, 3}], but I have no idea how I could get rid of all the rest. Does anybody know? Thanks a lot!

$\endgroup$
1
  • 1
    $\begingroup$ Both of your expression evaluate to a different form (run InputForm on either DateObject[{2008, 7, 3}, TimeObject[{0, 0, 0.}, TimeZone -> 2.], TimeZone -> 2.] or DateObject[{2008, 7, 3}]), so it isn't clear what it is you want to do with your DateObject. That being said, have a look at DayRound. $\endgroup$
    – Jason B.
    Commented Sep 14, 2018 at 18:35

2 Answers 2

2
$\begingroup$
dos = { DateObject[{2008, 7, 3}, TimeObject[{0, 0, 0.}, TimeZone -> 2.], TimeZone -> 2.] ,
  DateObject[{2008, 7, 4}, TimeObject[{0, 0, 0.}, TimeZone -> 2.], TimeZone -> 2.] }

enter image description here

f1 = DateObject[#,"Day"]&;
f1 /@ dos  

enter image description here

Alternatively, you can use

f2 = # /. DateObject[d_, ___] :> DateObject[d, "Day"]&;

f2 /@ dos == f /@ dos

True

$\endgroup$
2
$\begingroup$

You many use CurrentDate or DayRound.

dt = Now

Mathematica graphics

CurrentDate[dt, "Day"]

Mathematica graphics

DayRound[dt]

Mathematica graphics

Hope this helps.

$\endgroup$

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.