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
๐ŸŒ
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...
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
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
How can I format a date to MM/dd/yyyy in JavaScript? - TestMu AI Community
I have a date in the format '2010-10-11T00:00:00+05:30', and I need to convert it to the JavaScript date format MM/dd/yyyy. Can anyone help me with a solution using JavaScript or jQuery to achieve this format? More on community.testmu.ai
๐ŸŒ community.testmu.ai
0
February 17, 2025
How to convert date to dd-mm-yyyy in react
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-01-01T00:00:00) format to โ€œdd-mm-yyyyโ€. Thank you in advance More on forum.freecodecamp.org
๐ŸŒ forum.freecodecamp.org
0
November 19, 2020
๐ŸŒ
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 - Specific Date Format: To display a date in a specific format, such as DD/MM/YYYY, you can use Intl.DateTimeFormat with the appropriate options.
๐ŸŒ
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 โ€บ 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 = date.getUTCHours() var minutes = date.getUTCMinutes() var seconds = date.getUTCSeconds(); if (hours < 10) hours = "0" + hours; if (minutes < 10) minutes = "0" + minutes; if (seconds < 10) seconds = "0" + seconds; return cur_day + " " + hours + ":" + minutes + ":" + seconds; } console.log(NOW()); ... When formatting the time you are rounding every 5 minutes.
๐ŸŒ
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 ... const formatDateISO = (date) => { return date.toLocaleDateString('en-CA'); }; const currentDate = new Date(); console.log(formatDate...
๐ŸŒ
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?

Find elsewhere
๐ŸŒ
Microsoft Community Hub
techcommunity.microsoft.com โ€บ microsoft community hub โ€บ communities โ€บ products โ€บ content management โ€บ sharepoint developer
convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery ...
I'm attempting to use oListItem.set_item to insert date data into SharePoint from a custom form. I keep receiving "Request failed.String was not recognized as a valid DateTime. Essentially the date coming from the format of 2021-09-21 or (YYYY-MM-DD), it needs to be in the form of 09/21/2021(MM/DD/YYYY)
๐ŸŒ
Medium
trymysolution.medium.com โ€บ javascript-date-as-in-yyyy-mm-dd-hh-mm-ss-format-or-mm-dd-yyyy-hh-mm-ss-a0c96e8fa888
JavaScript Date as in YYYY-MM-DD hh:mm:ss Format or MM/DD/YYYY hh:mm:ss | by Yogesh D V | Medium
April 11, 2023 - function padTwoDigits(num: number) ... :::: // The function takes a Date object as a parameter and formats the date as YYYY-MM-DD hh:mm:ss....
๐ŸŒ
TestMu AI Community
community.testmu.ai โ€บ ask a question
How can I format a date to MM/dd/yyyy in JavaScript? - TestMu AI Community
February 17, 2025 - I have a date in the format '2010-10-11T00:00:00+05:30', and I need to convert it to the JavaScript date format MM/dd/yyyy. Can anyone help me with a solution using JavaScript or jQuery to achieve this format?
๐ŸŒ
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-โ€ฆ
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_date_formats.asp
W3Schools.com
Independent of input format, JavaScript ... standard for the representation of dates and times. The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format:...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-get-current-formatted-date-dd-mm-yyyy-in-javascript-and-append-it-to-an-input
How to get current formatted date dd/mm/yyyy in Javascript and append it to an input? - GeeksforGeeks
July 11, 2025 - The toLocaleDateString() method formats the date based on specified locales and options. To display dd/mm/yyyy, set the locale to 'en-GB'. Use the valueAsDate property to assign the current date as a Date object to an input field.
๐ŸŒ
Reddit
reddit.com โ€บ r/webdev โ€บ how get a date formatted like 2023-02-07 in js?
r/webdev on Reddit: How get a date formatted like 2023-02-07 in JS?
March 13, 2023 -

I'm going insane. I had this feature working perfectly. Took 2 weeks vacation. I come back and it's broken.

I know y'all will say this is impossible, but I was getting that format by using `date.toLocaleDateString('en-CA')`. I know the spec says that format is "dd/MM/yyyy", which isn't what I want, but I was giving me the format in the title, I swear to God.

This is such a stupid little thing but I've already spent hours on SO. It's just endless threads about people confused about datetimes and the differences between timezones and offsets and no one's talking about this silly little thing.

I have my new date: Wed Feb 08 2023 00:00:00 GMT-0500 (Eastern Standard Time)

I just need a simple operation to flip the string around so it becomes 2023-03-08

That is it. Please help

p.s. the date is always set to midnight user local time so offset can be ignored. Whatever day they're experiencing is the day to be formatted. Thank you

๐ŸŒ
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).