Get date X months ago

Published on August 30th, 2019

javascript icon

You actually can’t do this in one-liner. Can’t really understand why. Future me, please update this after that ‘AHA’ moment.

const threeMonthsAgo = new Date()
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3)

Still, can’t understand why getMonth works on new Date() but setMonth doesn’t. If you know why, seriously, send me email ([email protected]).