Published on

How to convert Date to YYYY-MM-DD format in Javascript

Authors

Here is how to convert date to YYYY-MM-DD format without using any third party library

const convertDate = dt => {
  const year = dt.getFullYear();
  const month = (dt.getMonth() + 1).toString().padStart(2, '0');
  const date = dt.getDate()
  return `${year}-${month}-${date}`
}

Happy formatted date!