Skip to content
Advertisement

Only retrieve YYYY-MM-DD from moment

Doing moment().format() returns 2018-05-30T11:38:04+10:00.

How can I retrieve only the 2018-05-30 part of it?

Advertisement

Answer

Here you go. You need to pass format string in moment().format("you desired date/time format in string format") function

let date = moment().format("YYYY-MM-DD");
console.log(date);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.js"></script>

For more information, checkout this link for formatting :

https://momentjs.com/docs/#/parsing/string-format/

Advertisement