age_on_date {diseasystore}R 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)
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)


[Package diseasystore version 0.3.0 Index]