Skip to contents

This function attempts to detect the format of a date string and convert it to the YYYY-MM-DD format.

Usage

date_to_yyyymmdd(date_str, smart_format = T, forceformat = "%Y.%m.%d")

Arguments

date_str

A character string representing a date in an unknown format.

smart_format

if it is T, then it will try to detect format. otherwise force format

forceformat

to make this effective, smart_format should be False

Examples

date_to_yyyymmdd('2022-02-28')
#> [1] "2022-02-28"
date_to_yyyymmdd('02/28/2022')
#> [1] "2022-02-28"
date_to_yyyymmdd('28.02.2022')
#> [1] "2022-02-28"
date_to_yyyymmdd('Feb 28, 2022')
#> [1] "2022-02-28"