Skip to contents

The deterministic core of the package: given a serial, a date system and a field order, there is exactly one answer and no inference takes place. Every other function in unexcel reduces to this one once it has established those three things – from the workbook itself (excel_date_system(), excel_date_cells()) when the .xlsx file is available, or from the arguments you supply when it is not.

Usage

serial_to_day_month(
  x,
  date_system = c("1900", "1904"),
  order = c("dm", "md"),
  output = c("numeric", "character")
)

Arguments

x

A numeric vector of Excel date serials (or anything coercible to one). Non-finite values and values that are not whole numbers are returned as NA, since a fractional serial is a time of day, not a mistyped day.month.

date_system

Either "1900" or "1904". Read it from the workbook with excel_date_system() rather than guessing; the default is "1900", which is what every current version of Excel writes.

order

"dm" for day.month (a value typed as 30.3 in a day-first locale) or "md" for month.day. unexcel_xlsx() takes this from each cell's number format code, so it need not be assumed.

output

"numeric" (the default) returns 30.3; "character" returns "30.3". Use "character" when trailing zeros matter – a value typed as 3.10 (3 October) is the number 3.1, and only the character form can tell it apart from a value typed as 3.1.

Value

A numeric or character vector the same length as x.

See also

excel_date_system() to read the date system from a workbook, unexcel_xlsx() to do the whole job from the file.

Examples

# 45746 is 2025-03-30 in the 1900 system
serial_to_day_month(45746)
#> [1] 30.3

# The same serial means a different date under the 1904 system
serial_to_day_month(45746, date_system = "1904")
#> [1] 31.3

# Month-first workbooks
serial_to_day_month(45746, order = "md")
#> [1] 3.3

# Keep the trailing zero of a value typed as "3.10"
serial_to_day_month(45933, output = "character")
#> [1] "3.10"