Next.js starter your AI actually understands. Ship internal tools in days not weeks. Pre-order $199 $499 → [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 with over 25 years of development experience, 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 Add a Tab in HTML
How to Add a Tab in HTML

How to Clone an Object in JavaScript
How to Clone an Object in JavaScript

How to Choose the Best Bootstrap Admin Template in 2026: Complete Buyer's Guide
How to Choose the Best Bootstrap Admin Template in 2026: Complete Buyer's Guide

How to get element ID in JavaScript
How to get element ID in JavaScript

Answers by CoreUI Core Team