Changing the date format

Hi all,
How I can change ny date format (yyyymmdd) to yyyy-mm (no days)

thanks

I am telling you by heart but something like this. Perhaps before doing you have to parse your date. But essentially, work with lubridate

library(lubridate)
df$your_date  <- ym(df$your_date)

Hi,
If your existing date is in character format you can use string functions to get your format.

stringr::str_sub(,1,6) #to get it as yyyymm

Or

paste0(str_sub(,1,4),"-",str_sub(,5,6)) # to get it as yyyy-mm

If your data is already in date format then pls use package lubridate for date manipulation as mentioned by @sirosdad

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.