The isSameYear
function from date-fns
allows you to compare two dates to check if they are in the same year. Here is an example of how to use it:
index.tsx306 chars12 lines
In the example above, we first import the isSameYear
function from the date-fns
library. We then create four Date
objects, two of which are in the same year and two that aren't. We then call the isSameYear
function with each of these date pairs as arguments, and true
is returned for the dates in the same year and false
is returned for the ones that aren't.
Note that the isSameYear
function only compares the year component of the dates, ignoring any other components like month, day, or time.
gistlibby LogSnag