Last active
February 24, 2023 14:42
-
-
Save michaeloyer/87eede65143b9a59261f16113e3665c1 to your computer and use it in GitHub Desktop.
Javascript DateString in the format yyyy-mm-dd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toDateString(date) { | |
const year = date.getFullYear(); | |
const month = date.getMonth() + 1; | |
const day = date.getDate(); | |
return `${year}-${month.toString().padStart(2,'0')}-${day.toString().padStart(2,'0')}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment