1

How to sort dates in Reactjs with the moment formatter? Tried this code and wont work

const sortByDate = (d1,d2) => {
  new Date(d2).getTime() - new Date(d1).getTime()
}

dateFormat = (firstDate, lastDate) => {
  let first = moment(new Date(firstDate).format("YYYY-MMM-DD")
  let last = moment(new Date(lastDate).format("YYYY-MMM-DD")
}
  return (sortByDate(first) + " - " + last)

Expected output should be like this

2022-01-01 - 2022-01-31
2022-02-01 - 2022-02-31
Oashi
  • 39
  • 7

0 Answers0