Quarter of year

JavaScript, Date · Oct 22, 2020

Returns the quarter and year to which the supplied date belongs to.

const quarterOfYear = (date = new Date()) => [
  Math.ceil((date.getMonth() + 1) / 3),
  date.getFullYear()
];

quarterOfYear(new Date('07/10/2018')); // [ 3, 2018 ]
quarterOfYear(); // [ 4, 2020 ]

More like this

  • Day of year

    Gets the day of the year (number in the range 1-366) from a Date object.

    JavaScript, Date · Oct 19, 2020

  • Week of year

    Returns the zero-indexed week of the year that a date corresponds to.

    JavaScript, Date · Aug 15, 2021

  • Number of days in month

    Gets the number of days in the given month of the specified year.

    JavaScript, Date · Jun 13, 2021