age_on_date: Compute the age (in years) on a given date

View source: R/age_helpers.R

age_on_dateR Documentation

Compute the age (in years) on a given date

Description

Provides the sql code to compute the age of a person on a given date.

Usage

age_on_date(birth, reference_date, conn)

Arguments

birth

(character(1))
Name of the birth date column.

reference_date

(Date(1) or character(1))
The date to compute the age for (or name of column containing the reference date).

conn

(DBIConnection or function)
A database connection or function that opens a database connection.

Value

SQL query that computes the age on the given date.

Examples


  conn <- SCDB::get_connection(drv = RSQLite::SQLite())

  dplyr::copy_to(conn, data.frame(birth = as.Date("2001-04-03"), "test_age")) |>
    dplyr::mutate(age = !!age_on_date("birth", as.Date("2024-02-28"), conn))

  DBI::dbDisconnect(conn)


diseasystore documentation built on April 4, 2025, 5:56 a.m.