Home > Net >  Change datetime format by removing the seconds
Change datetime format by removing the seconds

Time:06-14

I have a dataset with datetime data. The date is in yyyy-mm-dd hh:mm:ss format but I want it in dd-mm-yyyy hh:mm format. So without the seconds. How can I change this?

structure(list(Collectie_DatumTijd = structure(c(1626784620, 
1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 
1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 
1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 
1626784620), tzone = "UTC", class = c("POSIXct", "POSIXt"))), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))

CodePudding user response:

Use format.

format(x[,1], "%d-%m-%Y %H:%M")
# [1] "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37"
# [5] "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37"
# [9] "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37"
#[13] "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37"
#[17] "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37" "20-07-2021 12:37"

Data:

x <- structure(list(Collectie_DatumTijd = structure(c(1626784620, 
1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 
1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 
1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 1626784620, 
1626784620), tzone = "UTC", class = c("POSIXct", "POSIXt"))), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))
  • Related