Skip to contents

A tolerant detector: recognizes a calendar date or datetime in essentially any plausible written form (ISO, US, European, named-month, with or without time, 12/24-hour, T-separated, offsets, fractional seconds, weekday prefixes) by trying a library of strptime formats. Non-dates – counts, ZIPs, phones, ids, free text – are rejected by the in-range + round-trip guard.

Usage

is_date(x, min_year = 1900, max_year = 2100)

Arguments

x

A character vector.

min_year, max_year

Plausible calendar-year window (default 1900-2100).

Value

Logical vector; TRUE for a parseable in-range date/timestamp.

Examples

is_date(c("2016-03-15", "05/Mar/2016", "March 5, 2016 2:00 PM",
          "20160305T14:00:00Z", "banana", "12345"))
#> [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE