1

Currently when I wrap some output from PerformanceAnalytics package into datatable (DT package) for Shiny, the dates get T:00:00:00Z appended to them in the browser.

For example, 2015-01-31T00:00:00Z and want just 2015-01-31.

How do I prevent that happening and just show yyyy-mm-dd? Are there settings in datatable I am unaware of?

TEST CODE

# sample data from dput 
rets <- structure(c(NA, 0.00262056199999994, 0.000126308999435887, -0.00261834288319462, 
                       0.0367651429321201, -0.00809892429976078, 0.0139021665335084, 
                       -0.0134753927842055, -0.0140747519238918, -0.0163687182009664, 
                       -0.00980900143012819, 0.00832756801047285), 
                  class = c("xts","zoo"),
                  .indexCLASS = c("POSIXct", "POSIXt"), 
                  tclass = c("POSIXct", "POSIXt"),                 
                  .indexTZ = "UTC", tzone = "UTC",
                  index = structure(c(1414800000, 
                                      1417305600, 1419984000, 1422662400, 
                                      1425081600, 1427760000, 1430352000, 
                                      1433030400, 1435622400, 1438300800, 
                                      1440979200, 1443571200), 
                                    tzone = "UTC", 
                                    tclass = c("POSIXct",  "POSIXt")),
                                   .Dim = c(12L, 1L), 
                                   .Dimnames = list(NULL, "nav"))

library(PerformanceAnalytics)
library(DT)
library(xts)

DT::datatable(table.Drawdowns(rets))

WHAT TABLE LOOKS LIKE

drawdown-table

micstr
  • 5,080
  • 8
  • 48
  • 76

1 Answers1

2

You can use a formatting function, for example:

DT::datatable(table.Drawdowns(rets)) %>% formatDate(c(1,2,3), method = 'toDateString')

Gives: enter image description here

ROLO
  • 4,183
  • 25
  • 41
  • Thanks ROLO. Is formatDate baseR of part of tidyverse? – micstr Oct 18 '17 at 06:39
  • 1
    It is part of package DT. – ROLO Oct 18 '17 at 09:55
  • ran into this as well, but doesn't allow you to get a "%d-%m-%Y %H:%M:%S" format (non of the helper functions of DT give that format it seems), Got only date, only time, or with T/Z, or "summer time...." or "GMT" or "UTC" in the column: https://stackoverflow.com/questions/56818869/how-to-change-to-24-hour-format-in-datatables-in-r-shiny/56819674#56819674 and ended up using another approach – Mark Jul 09 '19 at 15:03