How can I get the start day to be considered when calculating the number of days in the whole month? #3070
Unanswered
BrunoLongo1
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Would simply adding a day to your end date before passing it to the diff function work? import { differenceInMonths, addDays } from "date-fns";
const earlier = new Date(2022, 0, 1);
const later = new Date(2022, 0, 31);
const res = differenceInMonths(addDays(later, 1), earlier);
console.log(res); // 1 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everybody ! Suppose I have the start date of 2022 - 01 - 01 and the end date of 2022 - 01 - 31. If I use the differenceInMonths function I get 0 as a result, as this function does not include the start day (01-01- 2022). How can I get a certain function that considers the start day, having the result for this interval as 1 ? that is, the function considers the start and end day and in this case it sees the full month, returning the result 1.
Thanks !
Beta Was this translation helpful? Give feedback.
All reactions