Skip to content

How do you know if today is an anniversary? #2539

Answered by fturmel
rserafim asked this question in Q&A
Discussion options

You must be logged in to vote

An anniversary needs to match the month and date but not the year. I suspect that the repo you were referencing doesn't work as intended because differenceInCalendarDays does takes into account years and can give you differences greater than 365 days. To make that countdown work, the year of one of the dates would need to be changed to match the other's.

Anyhow... if you really just want to check an anniversary, the following should work. You could use parse too, but parseISO fits your input format and is lighter. Good luck!

import { parseISO } from "date-fns";

function isAnniversary(date, anniversaryString) {
  const anniversary = parseISO(anniversaryString);
  return (
    date.getDate() 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rserafim
Comment options

Answer selected by rserafim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants