One data grid for JavaScript, React, Vue & Angular. Sorting, filtering, virtualization, pinning, and CSV export included. Early access $199 $349 → [Get it now]

How to format date as YYYY-MM-DD in JavaScript

Formatting dates as YYYY-MM-DD is crucial for database storage, API communication, and HTML date inputs across web applications. As the creator of CoreUI, I’ve handled date formatting in thousands of components and data processing scenarios. The most reliable and widely compatible approach is using toISOString() with string splitting to extract the date portion. This method ensures consistent ISO 8601 formatting regardless of timezone complexities.

Use toISOString().split('T')[0] to format any date as YYYY-MM-DD.

const formatted = new Date().toISOString().split('T')[0]

The toISOString() method converts the date to UTC and returns an ISO string like “2025-10-02T08:00:00.000Z”. The split('T')[0] extracts only the date part before the ‘T’ character, giving you “2025-10-02”. This approach handles all edge cases including month boundaries, leap years, and timezone differences automatically.

Best Practice Note:

This is the same method we use throughout CoreUI components for consistent date handling across different locales. For local timezone dates, use manual formatting with getFullYear(), getMonth() + 1, and getDate() instead.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
What is Double Question Mark in JavaScript?
What is Double Question Mark in JavaScript?

How to declare the optional function parameters in JavaScript?
How to declare the optional function parameters in JavaScript?

How to Merge Objects in JavaScript
How to Merge Objects in JavaScript

How to round a number to two decimal places in JavaScript
How to round a number to two decimal places in JavaScript