rdatetextsimplification

need to simplify a complex date


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 !


Solution

  • 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"