Convert Excel Dates to POSIXct
As I repeatedly forgot how to convert Excel dates to POSIX here's the specific function.
XLDateToPOSIXct(x, tz = "GMT", xl1904 = FALSE)
x |
the integer vector to be converted. |
tz |
a time zone specification to be used for the conversion, if one is required. See |
xl1904 |
logical, defining if the unspeakable 1904-system should be used. Default is FALSE. |
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.
return an object of the class POSIXct. Date-times known to be invalid will be returned as NA.
Andri Signorell <andri@signorell.net>
XLDateToPOSIXct(41025) XLDateToPOSIXct(c(41025.23, 41035.52))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.