-3

How to increase the day in this date string '2022-05-06' in JS? It can be both native and moments solution. I checked add method in moment but looks like I am doing something wrong and it doesn't work:

const date = '2022-05-06'
console.log(moment(date).add(1, 'days'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js"></script>
deceze
  • 510,633
  • 85
  • 743
  • 889
NewTech Lover
  • 1,185
  • 4
  • 20
  • 44

1 Answers1

1

You should parse string to moment object properly:

const date = '2022-05-06'
const newDate = moment(date,'YYYY-MM-DD').add(1, 'days');
Amirali Amirifar
  • 309
  • 1
  • 4
  • 13