Skip to content

function that tells if given date is in this week or Not. #3205

Answered by fturmel
Akhilbisht798 asked this question in General
Discussion options

You must be logged in to vote

@Akhilbisht798 I don't think there's a function to specifically handle this use case, but you can easily get there with startOfWeek:

import { startOfWeek } from "date-fns";

function isDateInCurrentWeek(date) {
  return startOfWeek(new Date()).getTime() === startOfWeek(date).getTime();
}

console.log(isDateInCurrentWeek(new Date(2022, 9, 4))); // true
console.log(isDateInCurrentWeek(new Date(2022, 9, 2))); // true
console.log(isDateInCurrentWeek(new Date(2022, 9, 1))); // false

@Pooja444 I'm not on the core team, so I can't confirm but there was a recent addition to the README that hints that it will. 9ecc9b2

Warning: the current main represents v3 pre-release version of the library. See v2

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by fturmel
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3200 on October 06, 2022 15:11.