-
I want to know how can I get previous month from the current date |
Beta Was this translation helpful? Give feedback.
Answered by
fturmel
May 16, 2022
Replies: 1 comment
-
Hi @ram027, You can try subMonths, or simply set the day of the month to const date = new Date(2022, 0, 15);
const previousMonth = new Date(date.getTime());
previousMonth.setDate(0);
console.log(date); // Sat Jan 15 2022 00:00:00 GMT-0500 (Eastern Standard Time)
console.log(previousMonth); // Fri Dec 31 2021 00:00:00 GMT-0500 (Eastern Standard Time) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tan75
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @ram027,
You can try subMonths, or simply set the day of the month to
0
on a date instance to change it to the last day of the previous month.