Get the number of calendar weeks a month spans.
Get the number of calendar weeks the month in the given date spans.
// CommonJS var getWeeksInMonth = require('date-fns/getWeeksInMonth')
// ES 2015 import getWeeksInMonth from 'date-fns/getWeeksInMonth'
// ESM import { getWeeksInMonth } from 'date-fns'
getWeeksInMonth(date, [options])
Name | Description |
---|---|
date |
the given date |
options |
an object with options. |
options.locale |
the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} |
options.weekStartsOn |
the index of the first day of the week (0 - Sunday) |
Description |
---|
the number of calendar weeks |
Type | Description |
---|---|
TypeError |
2 arguments required |
RangeError |
|
// How many calendar weeks does February 2015 span? const result = getWeeksInMonth(new Date(2015, 1, 8)) //=> 4
// If the week starts on Monday, // how many calendar weeks does July 2017 span? const result = getWeeksInMonth(new Date(2017, 6, 5), { weekStartsOn: 1 }) //=> 6
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/getWeeksInMonth