Examples for 'lubridate::ymd'


Parse dates with *y*ear, *m*onth, and *d*ay components

Aliases: ymd ydm mdy myd dmy dym yq ym my

Keywords: chron

### ** Examples

x <- c("09-01-01", "09-01-02", "09-01-03")
ymd(x)
[1] "2009-01-01" "2009-01-02" "2009-01-03"
x <- c("2009-01-01", "2009-01-02", "2009-01-03")
ymd(x)
[1] "2009-01-01" "2009-01-02" "2009-01-03"
ymd(090101, 90102)
[1] "2009-01-01" "2009-01-02"
now() > ymd(20090101)
[1] TRUE
## TRUE
dmy(010210)
[1] "2010-02-01"
mdy(010210)
[1] "2010-01-02"
yq('2014.2')
[1] "2014-04-01"
## heterogeneous formats in a single vector:
x <- c(20090101, "2009-01-02", "2009 01 03", "2009-1-4",
       "2009-1, 5", "Created on 2009 1 6", "200901 !!! 07")
ymd(x)
[1] "2009-01-01" "2009-01-02" "2009-01-03" "2009-01-04" "2009-01-05"
[6] "2009-01-06" "2009-01-07"
## What lubridate might not handle:

## Extremely weird cases when one of the separators is "" and some of the
## formats are not in double digits might not be parsed correctly:
## Not run: 
##D ymd("201002-01", "201002-1", "20102-1")
##D dmy("0312-2010", "312-2010")
## End(Not run)

[Package lubridate version 1.8.0 Index]