| formatDate {mStats} | R Documentation |
Format Dates
Description
formatDate converts characters or numbers to dates.
is.Date indicates which elements are Dates.
Usage
formatDate(x, format = "dmY", sep = "/", century = NULL)
is.Date(x)
year(x)
month(x)
day(x)
Arguments
x |
a character or numeric object |
format |
only for character vectors: |
sep |
separator character for date components |
century |
specify either 2000 or 1900 for two-digit years |
Details
dmy represents dd mm YYYY format.
In combination with separators from sep, this can change to
several date formats.
For example, dmy + - convert to
dd-mm-yyyy format.
Possible conversions
-
dmy+->>>dd-mm-yyyy -
dmy+/>>>dd/mm/yyyy -
mdy+/>>>mm/dd/yyyy -
ymd+/>>>yyyy/mm/dd -
dby+->>>dd-JAN-yy -
dby+/>>>dd/JAN/yy
Numeric conversions
Origin is set at 1899-12-30.
Author(s)
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
Examples
## convert strings to dates
x <- c("2019-01-15", "2019-01-20", "2019-01-21", "2019-01-22")
# check if it is a Date format
is.Date(x)
## Not run:
y <- formatDate(x, "Ymd", "-")
# check if it is a Date format
is.Date(y)
y
## another format
x <- c("22-JAN-19", "24-MAR-20")
y <- formatDate(x, "dby", "-")
is.Date(y)
y
## convert numbers to dates
x <- 42705:42710
y <- formatDate(x)
is.Date(y)
y
## get day, month or year
day(y)
month(y)
year(y)
## End(Not run)
[Package mStats version 3.4.0 Index]