Learn R Programming

DescTools (version 0.99.56)

XLDateToPOSIXct: Convert Excel Dates to POSIXct

Description

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

Usage

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

Value

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

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.

Author

Andri Signorell <andri@signorell.net>

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.

See Also

Examples

Run this code
XLDateToPOSIXct(41025)
XLDateToPOSIXct(c(41025.23, 41035.52))

Run the code above in your browser using DataLab