CoreUI ONE — 250+ PRO components and 25+ admin templates for React, Angular, Vue, Bootstrap and Next.js, plus Data Grid, Scheduler, 4,300+ PRO icons and the Next.js boilerplate. One license. → See what you get

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.
How to loop inside React JSX
How to loop inside React JSX

How to validate an email address in JavaScript
How to validate an email address in JavaScript

What is the difference between typeof and instanceof in JavaScript
What is the difference between typeof and instanceof in JavaScript

How to conditionally add attributes to React components
How to conditionally add attributes to React components