XLDateToPOSIXct: Convert Excel Dates to POSIXct

Description Usage Arguments Details Value Author(s) See Also Examples

Description

As I repeatedly forgot how to convert Excel dates to POSIX here's the specific function.

Usage

1
XLDateToPOSIXct(x, tz = "GMT", xl1904 = FALSE)

Arguments

x

the integer vector to be converted.

tz

a time zone specification to be used for the conversion, if one is required. See as.POSIXct.

xl1904

logical, defining if the unspeakable 1904-system should be used. Default is FALSE.

Details

XLGetRange will return dates as integer values, because XL stores them as integers. An Excel date can be converted with the (unusual) origin of as.Date(myDate, origin="1899-12-30"), which is implemented here.

Microsoft Excel supports two different date systems, the 1900 date system and the 1904 date system. In the 1900 date system, the first day that is supported is January 1, 1900. A date is converted into a serial number that represents the number of elapsed days since January 1, 1900. In the 1904 date system, the first day that is supported is January 1, 1904. By default, Microsoft Excel for the Macintosh uses the 1904 date system, Excel for Windows the 1900 system. See also: https://support.microsoft.com/en-us/kb/214330.

Value

return an object of the class POSIXct. Date-times known to be invalid will be returned as NA.

Author(s)

Andri Signorell <andri@signorell.net>

See Also

as.POSIXct

Examples

1
2
XLDateToPOSIXct(41025)
XLDateToPOSIXct(c(41025.23, 41035.52))

Example output

[1] "2012-04-26 GMT"
[1] "2012-04-26 05:31:12 GMT" "2012-05-06 12:28:47 GMT"

DescTools documentation built on June 17, 2021, 5:12 p.m.