1
$\begingroup$

I have downloaded some data:

mydata = FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}]

I would like to see them in a table where the date is formatted without the weekday and the time.

For example, I would want something like this:

-------------------
2014-11-5 | 2023.57
-------------------
2014-11-6 | 2031.21
-------------------
2014-11-7 | 2031.92
-------------------

Currently, I have only managed to display the data in a table but not to format the date:

Normal[TimeSeriesWindow[assetsUS, {{2014, 11, 5}, {2014, 11, 7}}]] // Grid

Is there a way to print it out in a table with borders as shown in the example above?

$\endgroup$

1 Answer 1

1
$\begingroup$

You can convert the DateObject to a formatted string with DateString. "ISODate" formats the string as YYY-MM-DD. MapAt[...,{All, 1}] applies it to the first element.

MapAt[DateString[#, "ISODate"] &, 
  Normal[TimeSeriesWindow[
    mydata, {{2014, 11, 5}, {2014, 11, 7}}]], {All, 1}] // Grid  

2014-11-05 2023.57
2014-11-06 2031.21
2014-11-07 2031.92

Or

MapAt[DateString[#, "ISODate"] &, 
  Normal[TimeSeriesWindow[
    mydata, {{2014, 11, 5}, {2014, 11, 7}}]], {All, 1}] // 
 Grid[#, Frame -> All, FrameStyle -> Directive[Gray, Dashed]] &

enter image description here

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