R/fm_yyyymm.R

Defines functions fm_yyyymm

Documented in fm_yyyymm

#' fm_yyyymm
#'
#' Convert date to yyyymm format
#'
#' @param date a date in format yyyy-mm-dd
#' @param hyphen use a hyphen in format: yyyy-mm
#'
#' @return character in format yyyymm
#'
#' @examples
#' fm_yyyymm("2021-05-01", hyphen = TRUE)
#'
#' @export
#'
fm_yyyymm <- function(date, hyphen = FALSE){
  date <- as.Date(date)

  stopifnot(lubridate::is.Date(date))

  if (hyphen) {
    format(date, "%Y-%m")
  } else {
    format(date, "%Y%m")
  }
}
mvbloois/faiR documentation built on Dec. 21, 2021, 11:04 p.m.