Working with dates in 2020 are still a mess. Presumably, they’ll also be a mess to work within 2021, 2022 and for a good while after that. Many (myself included) reach for a date library to fill the gaps.

For years Moment.js reigned supreme and for good reason, it can do everything with dates, including working with different time zones. Unfortunately, Moment can also result in bundle bloat.

And then came along date-fns. It could do almost everything Moment did and was good enough for 95% of all date and time related use cases. However, depending on the task, you can still use native vanilla Javascript to work with dates.

One such task I did recently was needing to calculate a day from today, my scenario was six months, but the solution I am going to show you can be changed to be any value and work for days and so on.

#javascript #programming #vanilla javascript

How To Calculate A JavaScript Date X Months Ago With Vanilla JavaScript
2.25 GEEK