-2

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'
Darren Tsai
  • 32,117
  • 5
  • 21
  • 51
Nupur Jain
  • 35
  • 5

1 Answers1

0

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"
UseR10085
  • 7,120
  • 3
  • 24
  • 54