Formatting and cleaning up a long date comlumn in R

Viewed 22

I have a date column that looks like this:

Dates
Sun Jan 30 04:00:35 UTC 2022
Thu Sep 02 20:21:52 UTC 2021
Tue Sep 20 14:41:17 UTC 2022
Thu Apr 08 16:19:21 UTC 2021
Wed Nov 03 16:20:45 UTC 2021

I was trying the following method but cannot figure out how to get ride of the Hour,minute, seconds and the two ":". In the end I just want to have the month (preferably in a 1-12 format), day and year.

mutate(last_login_date = gsub("UTC","",Dates),
       last_login_date = substr(Dates,5,25))
1 Answers

It may be easier to automatically convert to Date class with parse_date from parsedate

library(parsedate)
df1$Dates <- as.Date(parse_date(df1$Dates))
Related