1

How to convert 10-03-2021 into October-03-2021?

I have column in data frame in MM-DD-YYYY which needs to be converted into Month Name- Date- Year

example

10-03-2021 into October-03-2021

zx8754
  • 52,746
  • 12
  • 114
  • 209
ks ramana
  • 123
  • 5

1 Answers1

1

You have two parts: parsing the date, and then printing it with your format.

Parsing is quite easy with the lubridate package:

> library(lubridate)
> dates <- mdy(c('10-03-2021', '01-31-1995'))
> dates
[1] "2021-10-03" "1995-01-31"

For printing, you can then use the format() function:

> format(dates, '%B-%d-%Y')
[1] "October-03-2021" "January-31-1995"

%B is the full name of the month, %d the day and %Y the year (with all 4 digits)

tstenner
  • 10,080
  • 10
  • 57
  • 92