format_ym {dint}R Documentation

Coerce and Format to Year-Month Strings


Coerce and Format to Year-Month Strings


format_ym(x, m = NULL, format = "%Y-M%m")


x, m

Two integer (vectors). m is optional and the interpretation of x will depend on whether m is supplied or not:

  • if only x is supplied, x will be passed to as_date_ym() (e.g. x = 201604 means April 2016)

  • if x and m are supplied, x is interpreted as year and m as month.


A format that uses a subset of the same placeholders as base::strptime():

⁠%Y⁠ Year with century (the full year)
⁠%y⁠ Year without century (the last two digits of the year)
⁠%m⁠ Month as a decimal numbers (01-12)
⁠%B⁠ Full month name
⁠%b⁠ Abbreviated month name
⁠%V⁠ Week of the year as decimal number (01-53) as defined in ISO8601

Not all placeholders are supported for all date_xx subclasses. Literal "%" can be escaped with "%%" (as in base::sprintf()).


a character vector

Formatting shorthands

Format shorthand functions in the form of ⁠format_y*_[preset]()⁠ directly apply formatting presets to anything that can be coerced to a date_xx. This is notably handy as they can be used as a labeling function for ggplot2 axes (see vignette("dint"))

See Also


Other coerce and format functions: format_yq(), format_yw()


format_ym(2015, 5)
format_ym(201505, format = "short")
format_ym(201505, format = "shorter")

[Package dint version 2.1.4 Index]