-2

I have a csv file where the dates look like this: Jan 31, 2017

I would like it be 2017-01-31

I've been searching the site and I found a lot of similar questions but none with my strange date format.

EDIT: Was unclear. I need to change a lot of dates so doing it manually won't work. Thanks for suggestions, reading the help function of lubridate and strptime now.

Bugs
  • 4,491
  • 9
  • 32
  • 41

1 Answers1

3

Use the lubridate library:

library(lubridate)
date <- "Jan 31, 2017"
date2 <- mdy(date)

date2
[1] "2017-01-31"
roarkz
  • 811
  • 10
  • 22
  • Thank you for the very quick answer. I was a bit unclear though, I need to change all the dates in my file, doing it manually like this will be too time consuming. – Albert Alshamn Jul 18 '17 at 11:58
  • 2
    @AlbertAlshamn then do it for the column: `df1$newDate <- mdy(df1$oldDate)` – zx8754 Jul 18 '17 at 12:01