The eachWeekendOfMonth
function from the date-fns
library returns an array containing all weekends within the specified month.
To use the eachWeekendOfMonth
function, first, install the date-fns
library:
index.tsx21 chars2 lines
Then, import the eachWeekendOfMonth
function and pass in a date object that represents the month you want to get the weekend dates from:
index.tsx291 chars8 lines
In this example, we passed in 2021
as the year, and 10
as the month. Note that months are zero-indexed (January is 0, February is 1, etc.), so 10
represents November.
The eachWeekendOfMonth
function returns an array with all weekends in the given month. In this example, it returns an array with all weekend dates in November 2021.
gistlibby LogSnag