5.7 Format Strings

20240407

A common standard (based on strftime) for specifying a date format string will replace any %X special characters with specific components from the date (and time). For example, based on the result of a call to the function lubridate::now(), which is Sunday, 7 April 2024, 14:51:06 PM, the format is %A, %e %B %Y, %H:%M:%S %p.

The format strings that are available include:

  • %a \(\longrightarrow\) Sun (3 char day name)
  • %A \(\longrightarrow\) Sunday (full day name)
  • %b \(\longrightarrow\) Apr (3 char month name)
  • %B \(\longrightarrow\) April (full month name)
  • %d \(\longrightarrow\) 07 (01-31 leading 0 numeric day of month)
  • %e \(\longrightarrow\) 7 (1-31 numeric day of month)
  • %H \(\longrightarrow\) 14 (00-23 numeric 24 hours)
  • %I \(\longrightarrow\) 02 (01-11 numeric 12 hours)
  • %-I \(\longrightarrow\) 2 (1-11 numeric hours no leading 0)
  • %m \(\longrightarrow\) 04 (01-12 numeric month)
  • %M \(\longrightarrow\) 51 (00-59 numeric minutes)
  • %p \(\longrightarrow\) PM (AM,PM upper morning or afternoon)
  • %P \(\longrightarrow\) pm (am,pm lower morning or afternoon)
  • %S \(\longrightarrow\) 06 (00-60 numeric seconds)
  • %-S \(\longrightarrow\) 6 (0-60 numeric seconds no leading 0)
  • %y \(\longrightarrow\) 24 (00-99 2 digit year)
  • %Y \(\longrightarrow\) 2024 (4 digit year)
  • %Z \(\longrightarrow\) AEST (time zone)

A good resource is Fabrizio Musacchio’s strftime Cheat Sheet



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0