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 Saturday, 14 December 2024, 08:45:33 AM, the format is %A, %e %B %Y, %H:%M:%S %p.

The format strings that are available include:

  • %a \(\longrightarrow\) Sat (3 char day name)
  • %A \(\longrightarrow\) Saturday (full day name)
  • %b \(\longrightarrow\) Dec (3 char month name)
  • %B \(\longrightarrow\) December (full month name)
  • %d \(\longrightarrow\) 14 (01-31 leading 0 numeric day of month)
  • %e \(\longrightarrow\) 14 (1-31 numeric day of month)
  • %H \(\longrightarrow\) 08 (00-23 numeric 24 hours)
  • %I \(\longrightarrow\) 08 (01-11 numeric 12 hours)
  • %-I \(\longrightarrow\) 8 (1-11 numeric hours no leading 0)
  • %m \(\longrightarrow\) 12 (01-12 numeric month)
  • %M \(\longrightarrow\) 45 (00-59 numeric minutes)
  • %p \(\longrightarrow\) AM (AM,PM upper morning or afternoon)
  • %P \(\longrightarrow\) am (am,pm lower morning or afternoon)
  • %S \(\longrightarrow\) 33 (00-60 numeric seconds)
  • %-S \(\longrightarrow\) 33 (0-60 numeric seconds no leading 0)
  • %y \(\longrightarrow\) 24 (00-99 2 digit year)
  • %Y \(\longrightarrow\) 2024 (4 digit year)
  • %Z \(\longrightarrow\) AEDT (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