AsDate: Parse Character Dates To POSIXct Objects

View source: R/asdate.R

AsDateR Documentation

Parse Character Dates To POSIXct Objects

Description

Parse dates assuming some common (unknown) formats popular either in the U.S. or internationally

Usage

AsDate(x, us.format = NULL, exact = FALSE, on.parse.failure = "error")

ParseDates(x, us.format = NULL)

Arguments

x

character; vector of dates or date intervals/periods to be parsed, which should all be in the same format (excluding missing values). If timestamps are detected, they will be parsed using AsDateTime.

us.format

logical; whether to use the US convention for dates; can be NULL in which case both U.S. formats and international formats will be checked

exact

see parse_date_time2

on.parse.failure

Character string specifying how parse failures should be handled; "error", the default, results in an error being thrown with stop in the event that x cannot be parsed; specifying "warn" results in a warning be thrown and a vector of NA values with the same length as x; any other value results in a vector of NAs being returned silently.

Details

Time intervals or periods (start and end dates representing a specific time span) are also supported. If periods are detected in x, the starting date is parsed to class "Date" and returned. A wide-range of separators are supported and days are optional. The starting year also does not need to be supplied, though for numeric months, the format must be exactly ‘⁠"%m/%m %y⁠’ or ‘⁠"%m-%m %y"⁠’ (four-digit years will also work). See the examples.

ParseDates is deprecated and merely calls AsDate

Value

A vector of Date objects, if all elements of x have the same, valid format; otherwise, when on.parse.failure is not "error", a vector of NA values with the same length as x.

See Also

Date

Examples

AsDate("1-2-2017", us.format = FALSE)
AsDate("1-2-2017", us.format = TRUE)
AsDate("10/16/2016-2/10/2017")
AsDate("jun/sep 10")
AsDate("10-02 2011")
AsDate("10/02/2011", us.format = TRUE)
AsDate("feb 2016-jan 2017")
AsDate("31-05-2010 16-08-2011")
AsDate("2010-February")

NumbersInternational/flipTime documentation built on Feb. 26, 2024, 6:44 a.m.