Just leverage the built-in toISOString method that brings your date to the ISO 8601 format:

let yourDate = new Date()
yourDate.toISOString().split('T')[0]

Where yourDate is your date object.

Edit: @exbuddha wrote this to handle time zone in the comments:

const offset = yourDate.getTimezoneOffset()
yourDate = new Date(yourDate.getTime() - (offset*60*1000))
return yourDate.toISOString().split('T')[0]
Answer from Darth Egregious on Stack Overflow
🌐
CoreUI
coreui.io › answers › how-to-format-date-as-yyyy-mm-dd-in-javascript
How to format date as YYYY-MM-DD in JavaScript · CoreUI
September 30, 2025 - Format dates as YYYY-MM-DD using toISOString().split(“T”)[0] - the most reliable method for ISO date format in JavaScript.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
Independent of input format, JavaScript will (by default) output dates in full text string format: ISO 8601 is the international standard for the representation of dates and times. The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format:
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › date-tostring-format-yyyy-mm-dd
Format a JavaScript Date to YYYY MM DD - Mastering JS
const date = new Date(); const year = date.getFullYear() * 1e4; // 1e4 gives us the the other digits to be filled later, so 20210000. const month = (date.getMonth() + 1) * 100; // months are numbered 0-11 in JavaScript, * 100 to move two digits ...
🌐
Latenode
community.latenode.com › other questions › javascript
Convert date in JavaScript to yyyy-mm-dd format - JavaScript - Latenode Official Community
December 3, 2024 - I possess a date string in the form Sun May 11, 2014. What is the best way to transform it into the format 2014-05-11 using JavaScript? function formatDate(inputDate) { const dateObj = new Date(inputDate); const year = dateObj.getFullYear(); const month = String(dateObj.getMonth() + 1).padStart(2, '0'); const day = String(dateObj.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; } const date = 'Sun May 11, 2014'; console.log(formatDate(date)); The code snippet...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-javascript-date-as-yyyy-mm-dd
How To Format JavaScript Date as yyyy-mm-dd? - GeeksforGeeks
June 24, 2025 - Example: In this example, we will use the iso string method to format the JavaScript date as yyyy-mm-dd
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-format-javascript-date-as-yyyy-mm-dd.php
How to Format JavaScript Date as YYYY-MM-DD
// Create a date object from a ...ng("default", { day: "2-digit" }); // Generate yyyy-mm-dd date string var formattedDate = year + "-" + month + "-" + day; console.log(formattedDate); // Prints: 2022-05-04...
Find elsewhere
🌐
Squash
squash.io › how-to-format-javascript-date-as-yyyy-mm-dd
How to Format JavaScript Dates as YYYY-MM-DD
To format a JavaScript date as ... Here are two possible approaches: The toISOString() method returns a string representing the date in the ISO format (YYYY-MM-DDTHH:mm:ss.sssZ)....
🌐
freeCodeCamp
freecodecamp.org › news › how-to-format-a-date-with-javascript-date-formatting-in-js
How to Format a Date with JavaScript – Date Formatting in JS
November 7, 2024 - JavaScript provides a few built-in methods to format dates conveniently. Let's take a look at some of these methods: toDateString(): This method converts the date portion of a Date object into a human-readable string format.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
The format is as follows: ... YYYY is the year, with four digits (0000 to 9999), or as an expanded year of + or - followed by six digits. The sign is required for expanded years. -000000 is explicitly disallowed as a valid year. MM is the month, with two digits (01 to 12).
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-format-date-yyyymmdd
Format a Date as YYYY-MM-DD using JavaScript | bobbyhadz
Passing a locale of sv to the toLocaleDateString method returns a Date string formatted as YYYY-MM-DD.
🌐
Futurestud.io
futurestud.io › tutorials › how-to-format-a-date-yyyy-mm-dd-in-javascript-or-node-js
How to Format a Date YYYY-MM-DD in JavaScript or Node.js
In case you’re wondering about the provided getDay method in JavaScript: it returns the day of the week and not the day of the month. That’s why we’re using getDate. Here’s a sample format(date) function formatting the given date in YYYY-MM-DD: /** * Returns the `date` formatted in YYYY-MM-DD. * * @param {Date} date * * @returns {String} */ function format (date) { if (!(date instanceof Date)) { throw new Error('Invalid "date" argument.
Top answer
1 of 10
308

MM/DD/YYYY format

If you have the MM/DD/YYYY format which is default for JavaScript, you can simply pass your string to Date(string) constructor. It will parse it for you.

Copyvar dateString = "10/23/2015"; // Oct 23

var dateObject = new Date(dateString);

document.body.innerHTML = dateObject.toString();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

DD/MM/YYYY format - manually

If you work with this format, then you can split the date in order to get day, month and year separately and then use it in another constructor - Date(year, month, day):

Copyvar dateString = "23/10/2015"; // Oct 23

var dateParts = dateString.split("/");

// month is 0-based, that's why we need dataParts[1] - 1
var dateObject = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]); 

document.body.innerHTML = dateObject.toString();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

For more information, you can read article about Date at Mozilla Developer Network.

DD/MM/YYYY - using moment.js library

Alternatively, you can use moment.js library, which is probably the most popular library to parse and operate with date and time in JavaScript:

Copyvar dateString = "23/10/2015"; // Oct 23

var dateMomentObject = moment(dateString, "DD/MM/YYYY"); // 1st argument - string, 2nd argument - format
var dateObject = dateMomentObject.toDate(); // convert moment.js object to Date object

document.body.innerHTML = dateObject.toString();
Copy<script src="https://momentjs.com/downloads/moment.min.js"></script>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

In all three examples dateObject variable contains an object of type Date, which represents a moment in time and can be further converted to any string format.

2 of 10
14

Here's one I prepared earlier...

Copy  convertToDate(dateString) {
      //  Convert a "dd/MM/yyyy" string into a Date object
      let d = dateString.split("/");
      let dat = new Date(d[2] + '/' + d[1] + '/' + d[0]);
      return dat;     
  }
🌐
Byby
byby.dev › js-format-date
How to parse and format a date in JavaScript
Once a date is parsed in JavaScript and converted to a Date object, it can then be formatted into a string with a specific date format. There are different ways to format a date as dd/mm/yyyy in JavaScript, depending on your preference and use case.
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
Get the formatted date according to the string of tokens passed in. To escape characters, wrap them in square brackets (e.g. [MM]). dayjs().format() // current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00' dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYYescape 2019-01-25T00:00:00-02:00Z' dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
🌐
GitHub
gist.github.com › Ivlyth › c4921735812dd2c0217a
format javascript date to format "YYYY-mm-dd HH:MM:SS" · GitHub
function NOW() { var date = new Date(); var aaaa = date.getUTCFullYear(); var gg = date.getUTCDate(); var mm = (date.getUTCMonth() + 1); if (gg < 10) gg = "0" + gg; if (mm < 10) mm = "0" + mm; var cur_day = aaaa + "-" + mm + "-" + gg; var hours ...
🌐
Hyno
hyno.co › blog › format-javascript-date-as-yyyy-mm-dd-a-comprehensive-guide.html
Understanding format date in Javascript
The toISOString method is another option to format a date in JavaScript as yyyy-mm-dd. This method returns a string representation of the date in the ISO 8601 format. You can then extract the desired yyyy-mm-dd portion using string manipulation.
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
</p> <div className="card code-panel"> <div className="card-header example-title">Example: Date Conversion in Different Formats</div> <div className="panel-body"><pre className="csharpcode"><code>var date = new Date('2015-02-10T10:12:50.5000z'); date; 'Default format:' date.toDateString();'Tue Feb 10 2015' date.toLocaleDateString();'2/10/2015' date.toGMTString(); 'GMT format' date.toISOString(); '2015-02-10T10:12:50.500Z' date.toLocaleString();'Local date Format ' date.toLocaleTimeString(); 'Locale time format ' date.toString('YYYY-MM-dd'); 'Tue Feb 10 2015 15:42:50' date.toTimeString(); '15:42:50' date.toUTCString(); 'UTC format ' ... To get date string in formats other than the ones listed above, you need to manually form the date string using different date object methods.