Blog
Wild & Free Tools

Convert Unix Timestamp to YYYY-MM-DD Format

Last updated: April 2026 5 min read

Table of Contents

  1. Quick Reference
  2. Why YYYY-MM-DD
  3. Common Patterns
  4. Frequently Asked Questions

YYYY-MM-DD is the most useful date format for filenames, sorting, and database storage. It sorts correctly as a string (because year comes first), it has no ambiguity (unlike MM/DD/YYYY vs DD/MM/YYYY), and it is the ISO 8601 standard. The variant without dashes (YYYYMMDD) is even more common for filenames and partition keys.

Converting a Unix timestamp to either format is a one-liner in every language. This guide covers the patterns you actually need.

Unix Timestamp to YYYY-MM-DD — Quick Reference

LanguageYYYY-MM-DDYYYYMMDD
JavaScriptnew Date(ts*1000).toISOString().slice(0,10)same, with .replace(/-/g, "")
Pythondatetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d")strftime("%Y%m%d")
PHPdate("Y-m-d", $ts)date("Ymd", $ts)
MySQLDATE_FORMAT(FROM_UNIXTIME(ts), "%Y-%m-%d")DATE_FORMAT(FROM_UNIXTIME(ts), "%Y%m%d")
PostgreSQLto_char(to_timestamp(ts), "YYYY-MM-DD")to_char(to_timestamp(ts), "YYYYMMDD")
Snowflaketo_char(to_timestamp(ts), "YYYY-MM-DD")to_char(to_timestamp(ts), "YYYYMMDD")
BigQueryFORMAT_TIMESTAMP("%Y-%m-%d", TIMESTAMP_SECONDS(ts))FORMAT_TIMESTAMP("%Y%m%d", ...)
Bash (Linux)date -u -d @ts +%Y-%m-%ddate -u -d @ts +%Y%m%d

For a one-off conversion without writing code, paste your timestamp into the free Unix timestamp converter.

Sell Custom Apparel — We Handle Printing & Free Shipping

Why YYYY-MM-DD is the Right Format

Three reasons YYYY-MM-DD wins over every other date format for storage and filenames:

1. It sorts correctly as a string

If you sort filenames like backup-2024-03-21.sql alphabetically, they sort by date. The same is not true for MM-DD-YYYY (March files end up between January and April from the wrong year) or DD-MM-YYYY (day-1 of every month sorts before day-2 regardless of month).

2. It is unambiguous

Is "03/04/2024" March 4th or April 3rd? Depends on whether you are American (MM/DD) or European (DD/MM). YYYY-MM-DD has no ambiguity — year first, month second, day third, no negotiation.

3. It is the ISO 8601 standard

Every database, every programming language, every API spec accepts ISO 8601 dates. You can pass a YYYY-MM-DD string into SQL, JSON, or a config file and any system will parse it correctly.

When to use YYYYMMDD instead

The dashless version (20240321) is better for filenames where dashes would conflict with other parts of the name, and for partition keys in data warehouses where the partition column is a string. Same sortability, slightly more compact, less visual noise.

Common Use Cases for YYYY-MM-DD Conversion

Filename generation from timestamps

# Bash — daily backup file
filename="backup-$(date -u -d @1711000000 +%Y-%m-%d).sql"
# Result: backup-2024-03-21.sql

Date partition key from event timestamp

-- BigQuery — partition by event date
SELECT
    FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP_SECONDS(event_ts)) AS event_date,
    COUNT(*) AS event_count
FROM events
GROUP BY event_date

Log line date prefix

# Python — daily log rotation marker
import datetime
date_str = datetime.datetime.fromtimestamp(
    1711000000, tz=datetime.timezone.utc
).strftime('%Y-%m-%d')
# Result: "2024-03-21"

Display in user-facing UI

YYYY-MM-DD is also a perfectly fine display format for international audiences. American users sometimes find it less natural than "March 21, 2024", but everyone can read it without ambiguity. For UIs aimed at a global audience, YYYY-MM-DD is the safest default.

For language-specific deep dives see the Python timestamp guide or JavaScript timestamp guide.

Try It Free — No Signup Required

Runs 100% in your browser. No data is collected, stored, or sent anywhere.

Open Free Unix Timestamp Converter

Frequently Asked Questions

How do I convert a Unix timestamp to YYYY-MM-DD?

In JavaScript: new Date(ts*1000).toISOString().slice(0,10). In Python: datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d"). In SQL: depends on the database — DATE_FORMAT(FROM_UNIXTIME(ts), "%Y-%m-%d") in MySQL, to_char(to_timestamp(ts), "YYYY-MM-DD") in Postgres.

How do I get YYYYMMDD format without dashes?

Same approach as YYYY-MM-DD but use the format string without dashes. JavaScript: new Date(ts*1000).toISOString().slice(0,10).replace(/-/g, ""). Python: strftime("%Y%m%d"). MySQL: DATE_FORMAT(FROM_UNIXTIME(ts), "%Y%m%d").

Why is YYYY-MM-DD better than MM/DD/YYYY?

Three reasons: it sorts correctly as a string, it is unambiguous (no confusion between American and European date orders), and it is the ISO 8601 standard accepted by every database and API. For storage and filenames, YYYY-MM-DD always wins.

Should I use YYYY-MM-DD or YYYYMMDD for filenames?

Either works. YYYY-MM-DD is slightly more readable. YYYYMMDD is more compact and avoids potential conflicts with dashes elsewhere in the filename. Pick one and stick with it across your codebase.

How do I convert YYYY-MM-DD back to a Unix timestamp?

In JavaScript: Math.floor(new Date("2024-03-21").getTime() / 1000). In Python: int(datetime.strptime("2024-03-21", "%Y-%m-%d").replace(tzinfo=timezone.utc).timestamp()). The string is interpreted as UTC midnight by default in most languages.

Is YYYY-MM-DD the same as ISO 8601?

YYYY-MM-DD is the date portion of ISO 8601. The full ISO 8601 datetime includes time and timezone: 2024-03-21T07:46:40Z. The date-only form is technically ISO 8601 calendar date format, but in practice everyone calls it ISO 8601.

Launch Your Own Clothing Brand — No Inventory, No Risk