I have a character string date time string but need to convert the same into YYYYMM
date format. Cannot seem to find a solution as all functions are converting into NA
or weird date format.
Date_format_current <- '02/09/2020 23:35'
I have a character string date time string but need to convert the same into YYYYMM
date format. Cannot seem to find a solution as all functions are converting into NA
or weird date format.
Date_format_current <- '02/09/2020 23:35'
You can use the following code
library(lubridate)
library(zoo)
current <- '02/09/2020 23:35'
as.yearmon(dmy_hm(current))
#> [1] "Sep 2020"
#Or
format(dmy_hm(current), "%Y-%m")
#> [1] "2020-09"
#Or
format_ISO8601(dmy_hm(current), precision = "ym")
#> [1] "2020-09"