TFT

SQL Date & Time Function Playground

Experiment with SQL date functions in a live playground. Test DATE_ADD, DATEDIFF, EXTRACT, and more with your own inputs and see results instantly for MySQL, PostgreSQL.

SQL Date Function Playground

Explore and test date functions across different databases

Date Functions
Generated SQL

Select a function to generate SQL

How It Works

This SQL date function playground lets you experiment with date and time functions interactively, testing different operations and seeing results instantly without connecting to a database.

The playground process:

  1. Function selection: Choose from common date functions like DATE_ADD, DATEDIFF, DATE_FORMAT, EXTRACT, NOW, etc.
  2. Input configuration: Enter sample dates, intervals, or format strings as function parameters.
  3. Database dialect selection: Pick MySQL, PostgreSQL, SQL Server, or Oracle to see dialect-specific syntax and behavior.
  4. Result preview: See the function output immediately, along with the equivalent SQL query you can use in your code.

Date handling is notoriously tricky in SQL due to varying formats, time zones, and database-specific functions. This playground helps you get it right before writing production queries.

When You'd Actually Use This

Date Calculation Queries

Figure out how to calculate dates like '30 days ago' or 'next Monday' in SQL.

Report Generation

Build queries for monthly reports, year-to-date summaries, or period comparisons.

Data Filtering

Create WHERE clauses that filter records by date ranges, age, or relative time periods.

Learning SQL Date Functions

Understand how different date functions work and what parameters they accept.

Cross-Database Migration

Find equivalent date functions when migrating queries between different database systems.

Debugging Date Issues

Troubleshoot why date comparisons or calculations aren't producing expected results.

What to Know Before Using

Function names vary by database

DATE_ADD (MySQL) vs INTERVAL + (PostgreSQL) vs DATEADD (SQL Server). This tool shows the correct syntax for each database.

Date formats differ significantly

MySQL uses %Y-%m-%d, PostgreSQL uses ISO format, SQL Server depends on settings. Always specify format explicitly for portability.

Time zones complicate things

NOW() returns server time. For UTC, use UTC_NOW or equivalent. Time zone handling varies greatly between databases.

Date arithmetic has edge cases

Adding months to Jan 31 produces different results in different databases. End-of-month handling isn't standardized.

NULL handling in date functions

Most date functions return NULL if any input is NULL. Use COALESCE to provide defaults when needed.

Common Questions

How do I get the current date and time?

MySQL: NOW() or CURRENT_TIMESTAMP. PostgreSQL: NOW() or CURRENT_TIMESTAMP. SQL Server: GETDATE(). Oracle: SYSDATE. All return the database server's current date and time.

How do I add days, months, or years to a date?

MySQL: DATE_ADD(date, INTERVAL 1 MONTH). PostgreSQL: date + INTERVAL '1 month'. SQL Server: DATEADD(MONTH, 1, date). Oracle: ADD_MONTHS(date, 1).

How do I calculate the difference between two dates?

MySQL: DATEDIFF(date1, date2) returns days. PostgreSQL: date1 - date2 returns an interval. SQL Server: DATEDIFF(DAY, date2, date1). Results vary by database.

How do I extract year, month, or day from a date?

Most databases support EXTRACT(YEAR FROM date), EXTRACT(MONTH FROM date). MySQL also has YEAR(date), MONTH(date), DAY(date) functions.

How do I format dates for display?

MySQL: DATE_FORMAT(date, '%Y-%m-%d'). PostgreSQL: TO_CHAR(date, 'YYYY-MM-DD'). SQL Server: FORMAT(date, 'yyyy-MM-dd'). Format strings vary significantly.

How do I find records from the last N days?

WHERE date_column >= DATE_SUB(NOW(), INTERVAL 7 DAY) in MySQL. Adjust syntax for your database. This is common for recent activity queries.

What's the difference between DATE, DATETIME, and TIMESTAMP?

DATE stores only date. DATETIME stores date and time without timezone. TIMESTAMP stores date and time with timezone conversion. Choose based on your needs.