DEV Community

DbVisualizer
DbVisualizer

Posted on

SQL Add to Date: Simple Guide for MySQL, PostgreSQL, SQL Server & Oracle

Whether you’re calculating deadlines, setting expiration dates, or building event logic, SQL’s ability to add intervals to a date is essential.

In this quick guide, you'll learn how to add days, months, or years to dates in MySQL, PostgreSQL, SQL Server, and Oracle using the correct function for each.

Examples

MySQL

SELECT DATE_ADD('2024-01-06', INTERVAL 1 YEAR);
Enter fullscreen mode Exit fullscreen mode

PostgreSQL

SELECT '2024-03-17' + INTERVAL '1 day';
Enter fullscreen mode Exit fullscreen mode

SQL Server

SELECT DATEADD(month, 1, '2024-06-25');
Enter fullscreen mode Exit fullscreen mode

Oracle

SELECT TO_DATE('2024-11-15', 'YYYY-MM-DD') + 1 FROM DUAL;
Enter fullscreen mode Exit fullscreen mode

FAQ

Can I use the same syntax in all DBMSs?

No, each one uses a different function or operator.

Do results include time?

SQL Server often returns full DATETIME, others may only return DATE.

Can I use negative values?

Yes, to subtract time from a date.

Conclusion

Adding time to a date is a simple task with big impact—whether for automation, forecasting, or workflow logic. Each database system provides its own tools for it, and now you know how to use them correctly.

To test and compare these functions across different systems, try DbVisualizer—a tool built for cross-database productivity. Check out SQL Add to Date Operations: A Complete Guide for more insights.

Top comments (0)