Search code examples
rlubridate

How to get date type format?


I have a date in yyyymmdd format dataframe

ex.

df= data.frame(dat = seq.Date(from= as.Date("2021-01-01") , to = as.Date("2021-01-07"), by =1))

I want to create a column of strings in this format:

example : 2021-01-07 should look like 07-JAN-21


Solution

  • toupper(format(date_column, "%d-%b-%y"))
    

    here is the premise

    > df$dat <- toupper(format(df$dat, "%d-%b-%y"))
    > df
            dat
    1 01-JAN-21
    2 01-FEB-21
    3 01-MAR-21
    4 01-APR-21
    5 01-MAY-21
    6 01-JUN-21
    7 01-JUL-21