Is the given date in the same week as the current date?
Is the given date in the same week as the current date?
⚠️ Please note that this function is not present in the FP submodule as it uses
Date.now()internally hence impure and can't be safely curried.
// CommonJS
var isThisWeek = require('date-fns/isThisWeek')
// ES 2015 import isThisWeek from 'date-fns/isThisWeek'
// ESM
import { isThisWeek } from 'date-fns'
isThisWeek(date, [options])
| Name | Description |
|---|---|
date |
the date to check |
options |
the 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 date is in this week |
| Type | Description |
|---|---|
TypeError |
1 argument required |
RangeError |
|
// If today is 25 September 2014, is 21 September 2014 in this week? const result = isThisWeek(new Date(2014, 8, 21)) //=> true
// If today is 25 September 2014 and week starts with Monday
// is 21 September 2014 in this week?
const result = isThisWeek(new Date(2014, 8, 21), { weekStartsOn: 1 })
//=> false
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/isThisWeek