Connor Hill
Connor Hill

Reputation: 49

Converting Date Column from "YYYYMMDD" and "DD-MMM-YY" to "DD/MM/YYYY"

I have a date column that has a combination of the two following date types: "YYYYMMDD" and "DD-MMM-YY" I am wanting to convert the column to a "DD/MM/YYYY". Below is an example of what it looks like:

Birth_Day|
20021019 |
20021024 |
24-Oct-02|
26-Oct-02|

I am wanting to convert it to:

Birth_Day |
19/10/2002|
24/10/2002|
24/10/2002|
26/10/2002|

Upvotes: 0

Views: 220

Answers (1)

akrun
akrun

Reputation: 887911

We may use parse_date with format

library(parsedate)
df1$Birth_Day <- format(parse_date(df1$Birth_Day), "%d/%m/%Y")

-output

> df1
   Birth_Day
1 19/10/2002
2 24/10/2002
3 24/10/2002
4 26/10/2002

data

df1 <- structure(list(Birth_Day = c("20021019", "20021024", "24-Oct-02", 
"26-Oct-02")), class = "data.frame", row.names = c(NA, -4L))

Upvotes: 1

Related Questions