Answers for "how to get 6 months after date object"

0

how to get 6 months after date object

const getDaysInMonth = (year, month) => new Date(year, month, 0).getDate()

const addMonths = (input, months) => {
  const date = new Date(input)
  date.setDate(1)
  date.setMonth(date.getMonth() + months)
  date.setDate(Math.min(input.getDate(), getDaysInMonth(date.getFullYear(), date.getMonth()+1)))
  return date
}
Posted by: Guest on March-20-2021

Code answers related to "how to get 6 months after date object"

Browse Popular Code Answers by Language