Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date time values are displayed broken in DT:datatable()

Tags:

datetime

r

dt

I have the dataframe below and I want to display it as DT::datatable()

library(DT)
library(lubridate)
eventex <- structure(list(registration_type = c("Start", "Stopp"),
                         timestamp = c("25.11.2022 13:19:42", 
                                       "31.10.2022 14:19:13")),
                         row.names = c(NA, -2L), 
                         class = c("tbl_df", "tbl", "data.frame"))

eventex$timestamp<-as.POSIXct( paste0(eventex$timestamp),
                               format="%d.%m.%Y %H:%M:%S")

datatable(eventex)

why is it displayed like this? enter image description here

like image 830
firmo23 Avatar asked Nov 19 '25 17:11

firmo23


1 Answers

People's definition of "normal" may vary, especially when ambiguous (and irrational) conventions such as commonly used in the US are assumed. There is a formatDate function that can be applied to your datetime column. (The options are not well documented in the R package):

DT:::DateMethods
[1] "toDateString"       "toISOString"        "toLocaleDateString" "toLocaleString"     "toLocaleTimeString"
[6] "toString"           "toTimeString"       "toUTCString"   

datatable(eventex) %>% formatDate(~timestamp, "toLocaleString" )

enter image description here

Further information and worked examples can be found here: https://rstudio.github.io/DT/functions.html

like image 170
IRTFM Avatar answered Nov 21 '25 07:11

IRTFM