The fmt_duration() function

Use part of the sp500 table to create a gt table. Create a difftime-based column and format the duration values to be displayed as the number of days since March 30, 2020.

sp500 |>
  dplyr::slice_head(n = 10) |>
  dplyr::mutate(
    time_point = lubridate::ymd("2020-03-30"),
    time_passed = difftime(time_point, date)
  ) |>
  dplyr::select(time_passed, open, close) |>
  gt(rowname_col = "month") |>
  fmt_duration(
    columns = time_passed,
    output_units = "days",
    duration_style = "wide"
  ) |>
  fmt_currency(columns = c(open, close))
time_passed open close
1,551 days $2,060.59 $2,043.94
1,552 days $2,077.34 $2,063.36
1,553 days $2,060.54 $2,078.36
1,554 days $2,057.77 $2,056.50
1,558 days $2,063.52 $2,060.99
1,559 days $2,042.20 $2,064.29
1,560 days $2,023.15 $2,038.97
1,561 days $2,010.27 $2,021.15
1,564 days $2,040.81 $2,005.55
1,565 days $2,073.76 $2,041.89