When using the read_excel function the dates in the spreadsheet, in the column FuelEventDateTime, are in format "dd/mm/yyyy hr:mm:ss" (example: 03/05/2019 9:19:00 AM) is parsed as a character string with a format like this: example: 43588.849xxxxx (being x any number). I cannot set this column to the correct date class, and I don't know what that number can mean but have seen it several times in Excel.
Tried to separate the "." in the character string, set the column as.numeric, and tried several functions in lubridate, R base and anydate library, as maybe that number is a date in epoch format in origin "1900-01-01"
Read data
sys_raw <- read_excel("Advanced Fill-Ups Report 15052019_165240.xlsx", sheet = "Data", col_names = FALSE)
col_names_sys <- sys_raw[11,]
sys_tidy <- sys_raw[12:ncol(sys_raw),] %>%
setNames(col_names_sys) %>%
select(DeviceName, FuelEventDateTime,FuelUsedEventDistance)
Noticed the character string as numbers, tried separate "." and set as numeric
sys_tidy <- sys_tidy %>%
mutate(FuelEventDateTime = str_split(FuelEventDateTime, "\\.")) %>%
separate(FuelEventDateTime, c("c","date","time")) %>%
separate(DeviceName, c("Device"), sep = "\\s") %>%
select(Device, date, FuelUsedEventDistance) %>%
mutate(date = as.numeric(date))
sys_tidy <- sys_tidy %>%
as.Date(date, origin = "1900-01-01")
Actual results of this are errors, the expected result is a column date with a date class in the format "dd/mm/yyyy", don't need time.
Example of error messages:
Error in as.Date.default(., date, origin = "1900-01-01") :do not know how to convert '.' to class “Date”
Error in as.POSIXct.default(., date, origin = "1900-01-01") :do not know how to convert '.' to class “POSIXct”