The fmt_datetime() function

Use exibble to create a gt table. Keep only the datetime column. Format the column to have dates formatted with the "month_day_year" style and times with the "h_m_s_p" 12-hour time style.

exibble |>
  dplyr::select(datetime) |>
  gt() |>
  fmt_datetime(
    columns = datetime,
    date_style = "month_day_year",
    time_style = "h_m_s_p"
  )
datetime
January 1, 2018 2:22:00 AM
February 2, 2018 2:33:00 PM
March 3, 2018 3:44:00 AM
April 4, 2018 3:55:00 PM
May 5, 2018 4:00:00 AM
June 6, 2018 4:11:00 PM
July 7, 2018 5:22:00 AM
NA

Using the same input table, we can use flexible date and time styles. Two that work well together are "MMMEd" and "Hms". These will mutate depending on the locale. Let’s use the default locale for the first 3 rows and the Danish locale ("da") for the remaining rows.

exibble |>
  dplyr::select(datetime) |>
  gt() |>
  fmt_datetime(
    columns = datetime,
    date_style = "MMMEd",
    time_style = "Hms",
    locale = "da"
  ) |>
  fmt_datetime(
    columns = datetime,
    rows = 1:3,
    date_style = "MMMEd",
    time_style = "Hms"
  )
datetime
Mon, Jan 1 02:22:00
Fri, Feb 2 14:33:00
Sat, Mar 3 03:44:00
ons 4. apr. 15.55.00
lør 5. maj 04.00.00
ons 6. jun. 16.11.00
lør 7. jul. 05.22.00
NA

It’s possible to use the format argument and write our own formatting specification. Using the CLDR datetime pattern "EEEE, MMMM d, y 'at' h:mm a (zzzz)" gives us datetime outputs with time zone formatting. Let’s provide a time zone ID ("America/Vancouver") to the tz argument.

exibble |>
  dplyr::select(datetime) |>
  gt() |>
  fmt_datetime(
    columns = datetime,
    format = "EEEE, MMMM d, y 'at' h:mm a (zzzz)",
    tz = "America/Vancouver"
  )
datetime
Monday, January 1, 2018 at 2:22 AM (Pacific Standard Time)
Friday, February 2, 2018 at 2:33 PM (Pacific Standard Time)
Saturday, March 3, 2018 at 3:44 AM (Pacific Standard Time)
Wednesday, April 4, 2018 at 3:55 PM (Pacific Daylight Time)
Saturday, May 5, 2018 at 4:00 AM (Pacific Daylight Time)
Wednesday, June 6, 2018 at 4:11 PM (Pacific Daylight Time)
Saturday, July 7, 2018 at 5:22 AM (Pacific Daylight Time)
NA