0

I have about 200,000 records that have dates as text in this format: Monday, March 01, 2018 and need to be converted to this format: 03-01-2018. A solution using XL or R would work. The key here is that the final text needs to be able to be used as a date for sorting and selecting. I don't need the day of week info.

Thanks all !

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
xtufer
  • 149
  • 8

1 Answers1

1

I figured it out ...

test is a vector of dates in the form ... "Monday, March 01, 2018"

test[grepl("[,.,]",test)] <- format(as.Date(test[grepl("[,.,]",test)],cur_date_form), des_date_form)

where cur_date_form is "%A, %B %d, %Y" and des_date_form is "%m-%d-%Y"

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
xtufer
  • 149
  • 8
  • this looks reasonable, but it's not at all clear what the `grepl(...)` clauses are doing. As written I believe that these should select any element that contains a dot (`.`) or a comma ... ? – Ben Bolker Oct 31 '20 at 17:21