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
🌐
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).
Discussions

Convert date in JavaScript to yyyy-mm-dd format
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, ... More on community.latenode.com
🌐 community.latenode.com
0
December 3, 2024
html - How to get current formatted date dd/mm/yyyy in Javascript and append it to an input - Stack Overflow
I would like to add a current date to a hidden HTML tag so that it can be sent to the server: How can I add a More on stackoverflow.com
🌐 stackoverflow.com
Javascript date format dd/mm/yy NOT dd/mm/yyyy - do I need to import a library?
I am developing a software simulation which uses dates/ calendars extensively. (a booking system) Some javascript has already been used in this project, for... More on community.articulate.com
🌐 community.articulate.com
12
0
June 8, 2017
Weird JavaScript date problem: new Date('MM/dd/yyyy') !== new Date('yyyy-MM-dd')
It is consistent: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse . A huge mess, but consistent and specified. More on reddit.com
🌐 r/javascript
13
4
August 8, 2014
🌐
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 ... as yyyy-mm-dd ... const formatDateISO = (date) => { return date.toLocaleDateString('en-CA'); }; const currentDate = new Date(); console.log(formatDateISO(currentDate)); ... In this method, ...
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
W3Schools.com
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... The ISO format follows a strict standard in JavaScript. The other formats are not so well defined and might be browser specific. 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:
🌐
freeCodeCamp
freecodecamp.org › news › javascript-date-now-how-to-get-the-current-date-in-javascript
JavaScript Date Now – How to Get the Current Date in JavaScript
June 15, 2020 - const formatMap = { mm: date.getMonth() + 1, dd: date.getDate(), yy: date.getFullYear().toString().slice(-2), yyyy: date.getFullYear() };
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-3.php
JavaScript: Display the current date in various format - w3resource
// Get the current date var today ... (mm < 10) { mm = '0' + mm; } // Format the date as mm-dd-yyyy and log it today = mm + '-' + dd + '-' + yyyy; console.log(today); // Format the date as mm/dd/yyyy and log it today = mm + '/' ...
Find elsewhere
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - const date = new Date(); const ... 0-11, so add 1 const day = String(date.getDate()).padStart(2, '0'); const formattedDate = `${year}-${month}-${day}`; console.log(formattedDate); // outputs date in yyyy-mm-dd format · You ...
🌐
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...
🌐
GitHub
gist.github.com › mohokh67 › e0c5035816f5a88d6133b085361ad15b
Get YYYY-MM-DD HH-MM-SS in JavaScript · GitHub
Clone this repository at &lt;script src=&quot;https://gist.github.com/mohokh67/e0c5035816f5a88d6133b085361ad15b.js&quot;&gt;&lt;/script&gt; Save mohokh67/e0c5035816f5a88d6133b085361ad15b to your computer and use it in GitHub Desktop. Download ZIP · Get YYYY-MM-DD HH-MM-SS in JavaScript · Raw · timestamp-formatter.md · const formatedTimestamp = ()=> { const d = new Date() const date = d.toISOString().split('T')[0]; const time = d.toTimeString().split(' ')[0].replace(/:/g, '-'); return `${date} ${time}` } Sign up for free to join this conversation on GitHub.
🌐
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
January 5, 2023 - /** * 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.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › date-tostring-format-yyyy-mm-dd
Format a JavaScript Date to YYYY MM DD - Mastering JS
Mastering JS · Tutorials Newsletter ... a date to YYYYMMDD in JavaScript, you can use the toLocaleDateString() function in combination with the split(), reverse(), and join() functions....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-current-formatted-date-dd-mm-yyyy-in-javascript
How to Get Current Formatted Date dd/mm/yyyy in JavaScript? - GeeksforGeeks
July 11, 2025 - // Get current date const today ... = month < 10 ? '0' + month : month; // Format the date as dd/mm/yyyy const formattedDate = `${day}/${month}/${year}`; console.log(formattedDate);...
🌐
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 ...
🌐
Reddit
reddit.com › r/javascript › weird javascript date problem: new date('mm/dd/yyyy') !== new date('yyyy-mm-dd')
r/javascript on Reddit: Weird JavaScript date problem: new Date('MM/dd/yyyy') !== new Date('yyyy-MM-dd')
August 8, 2014 -

Some day, someone will invent a JavaScript compiler that handles dates in a consistent manner. Sadly, today is not that day. I'm having an issue where two identical dates that are parsed from differently formatted strings are producing two different results.

For example,

new Date('08/01/2014')

will result in a value of "Fri Aug 01 2014 00:00:00 GMT-0400 (Eastern Daylight Time)", as expected.

However,

new Date('2014-08-01')

gives "Thu Jul 31 2014 20:00:00 GMT-0400 (Eastern Daylight Time)". An offset of 4 hours. Basically, what happens is that using the MM/dd/yyyy format uses the local timezone and yyyy-MM-dd uses UTC.

Now the weirder part: appending midnight, "00:00:00", to the date value gives the expected result regardless of which of the two formats are used.

This happens in Chrome, Firefox, and IE. I have not tested Safari and Opera but, since they both use Webkit, I expect the same problem.

I can code around this easily enough but does anyone know the reasoning behind this?

🌐
UiPath Community
forum.uipath.com › help › activities
How to get date in format "MM/dd/yy" - Activities - UiPath Community Forum
May 18, 2023 - Greeting everybody. I need to read a datatable that comes from a website and get the text from a specfic column. That cell contains the date in the format “MM/dd/yy” which I will compare to today’s date to get the time f…
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
How to convert date to dd-mm-yyyy in react
November 19, 2020 - Hi, I am new to react (just three days) and I currently doing a project using my past experience in Jquery and ASP.NET to write the project. The challenge I am currently having now is how to convert date in JSON (2018-…