compute_age: Compute time interval between two dates

compute_ageR Documentation

Compute time interval between two dates

Description

Calculate the time difference between two dates in specified units (years, months, or days). Uses lubridate intervals for accurate calculations across calendar irregularities.

Usage

compute_age(date_start, date_end, unit = c("years", "months", "days"))

Arguments

date_start

Starting date. Must be a date or datetime object compatible with lubridate.

date_end

Ending date. Must be a date or datetime object compatible with lubridate.

unit

Character string specifying the unit for the result. Must be one of "years", "months", or "days". Defaults to "years".

Value

A numeric value representing the time difference in the specified unit.

Examples

# Calculate age in years
compute_age(as.Date("1990-01-01"), as.Date("2024-01-01"))

# Calculate age in months
compute_age(as.Date("2023-01-01"), as.Date("2024-01-01"), unit = "months")

# Calculate age in days
compute_age(as.Date("2023-12-01"), as.Date("2024-01-01"), unit = "days")


ABCDscores documentation built on Sept. 11, 2025, 5:08 p.m.