Published on

How to convert Date to YYYY-MM-DD format in Day.js

Authors

Here is how to convert date to YYYY-MM-DD format by using day.js

Install the dependency if it's not already done.

npm install dayjs
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat.js";
dayjs.extend(customParseFormat);

const formattedDate = dayjs().format("YYYY-MM-DD") // 2023-03-01

Happy formatted date!