Days and Months Operation

by Faisal Khan Janjua

JavaScript

addDays = (date, n) => new Date(date.setDate(date.getDate() + n));
subtractDays = (date, n) => new Date(date.setDate(date.getDate() - n));
addMonths = (date, n) => new Date(date.setMonth(date.getMonth() + n));


let opts = { month: 'short', day: '2-digit', year: 'numeric' };

console.log('Date after 7 days will be:', addDays(new Date(), 7).toLocaleString('en-pk', opts));
console.log('Date 7 days ago was: ', subtractDays(new Date(), 7).toLocaleString('en-pk', opts));
console.log('Date after 7 months will be:', addMonths(new Date(), 7).toLocaleString('en-pk', opts));