How to calculate the start and end dates of the previous month using moment

How to calculate the start and end dates of the previous month using moment

When managing dates, it is good practice to choose only one robust library and stick to it. To look up later, I wanted to keep one specific moment.js usage here.

Solution

Start date of the previous month

const startDate = moment().add(-1, 'months').startOf('month');

End date of the previous month

const endDate = moment().add(-1, 'months').endOf('month');

Conclusion

Thank you for reading! I hope you have found this post helpful.

Reference