Skip to contents

Quarters divide the year into fourths. Semesters divide the year into halfs.

Usage

fiscal_quarter(
  x,
  with_year = TRUE,
  fiscal_start = 1,
  format = c("numeric", "string")
)

Arguments

x

a date-time object of class POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, fts or anything else that can be converted with as.POSIXlt

with_year

logical indicating whether or not to include the quarter's year.

fiscal_start

numeric indicating the starting month of a fiscal year

Value

numeric

Examples

x <- as.Date(c("2023-01-15", "2023-04-01", "2023-07-20", "2023-10-31"))
fiscal_quarter(x, with_year = FALSE)            # Returns: 1, 2, 3, 4
#> [1] 1 2 3 4
fiscal_quarter(x, with_year = TRUE)             # Returns: 2023.1, 2023.2, 2023.3, 2023.4
#> [1] 2023.1 2023.2 2023.3 2023.4
fiscal_quarter(x, with_year = TRUE, fiscal_start = 4)  # Returns: 2022.4, 2023.1, 2023.2, 2023.3
#> [1] 2022.4 2023.1 2023.2 2023.3
fiscal_quarter(x, format = "string")            # Returns: "2023-Q1", "2023-Q2", "2023-Q3", "2023-Q4"
#> [1] "2023-Q1" "2023-Q2" "2023-Q3" "2023-Q4"
fiscal_quarter(x, with_year = FALSE, fiscal_start = 7)             # Returns: 3, 4, 1, 2
#> [1] 3 4 1 2