lubridate icon indicating copy to clipboard operation
lubridate copied to clipboard

Feature request: Excel date origin

Open NickCH-K opened this issue 1 year ago • 4 comments

lubridate is an extremely good package for handling dates and date conversion. However, it does not accept perhaps one of the most common forms of date data: dates from Excel. Thankfully, many Excel-file-reading functions do this conversion for you, but when they don't it's always one more time Googling to figure out how to convert properly (or, worse, not realizing how oddly Excel handles dates and getting things 70 years off).

The actual task here is very easy, since it just requires setting origin = "1899-12-30". There are many ways this could be implemented, but one simple approach would be, since there is already lubridate::origin, to also have lubridate::excel_origin set to as.POSIXct('1899-12-30').

Maybe this is a bit left-field, but after Googling the correct date for the fiftieth time it occurs to me that this would be a useful convenience function.

NickCH-K avatar Jul 17 '24 02:07 NickCH-K

but when they don't it's always one more time Googling to figure out how to convert properly (or, worse, not realizing how oddly Excel handles dates and getting things 70 years off).

I don't particularly mind having excel_origin in the package, but the actual use case is not clear to me. How exactly is supposed that value to help and in which circumstances?

vspinu avatar Dec 05 '24 21:12 vspinu

but when they don't it's always one more time Googling to figure out how to convert properly (or, worse, not realizing how oddly Excel handles dates and getting things 70 years off).

I don't particularly mind having excel_origin in the package, but the actual use case is not clear to me. How exactly is supposed that value to help and in which circumstances?

The use case is when you have a data file that, upon import, gives Excel-date-format-integers for numbers (i.e. 45123 or '45123') instead of dates. This sometimes occurs when reading in Excel data directly, or if a file passed through Excel at some point and was exported to another format that did not preserve the date formatting of the date column. I run into this quite frequently when using Excel sheets or CSVs prepared by others or downloaded from the internet.

NickCH-K avatar Dec 05 '24 22:12 NickCH-K

How different would adding this function be from using janitor::excel_numeric_to_date()? Not saying it is not an idea to explore, just thinking if what you are asking for can be achieved already, albeit with an additional package.

Edgar-Zamora avatar Jan 30 '25 00:01 Edgar-Zamora

I was not aware of that function! I don't think it would be much different at all, which means the only benefit here would be collecting date-based convenience functions into lubridate as opposed to being scattered elsewhere.

NickCH-K avatar Jan 30 '25 00:01 NickCH-K