How to Get Yesterday's Date in MySQL
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Retrieving yesterday’s date in MySQL requires you to use the CURDATE() or NOW() functions combined with the INTERVAL keyword. This guide will show you how to calculate and manipulate dates in MySQL, focusing on obtaining yesterday’s date in different formats.
MySQL provides several functions for date and time operations. The two commonly used for getting the current date are CURDATE() and NOW(). CURDATE() returns the current date without time, while NOW() returns both date and time.
SELECT CURDATE() as CurrentDate, NOW() as CurrentDateTime;
To get yesterday’s date, subtract one day from the current date. Use the INTERVAL keyword with CURDATE() or NOW().
SELECT CURDATE() - INTERVAL 1 DAY as YesterdayDate;
MySQL’s DATE_FORMAT() function allows formatting the date output. For instance, to get yesterday’s date in a specific format, combine DATE_FORMAT() with the date calculation.
SELECT DATE_FORMAT(CURDATE() - INTERVAL 1 DAY, '%Y-%m-%d') as FormattedYesterdayDate;
Retrieving records based on yesterday’s date is a common use case. For example, to find all entries from a logs table that occurred yesterday:
SELECT *
FROM logs
WHERE DATE(log_date) = CURDATE() - INTERVAL 1 DAY;
When working with time zones, use CONVERT_TZ() in conjunction with date functions. This ensures the date calculations respect the desired time zone.
SELECT CONVERT_TZ(CURDATE(), '+00:00', 'America/New_York') - INTERVAL 1 DAY as YesterdayDateInNY;
Manipulating dates in MySQL is straightforward with functions like CURDATE() and DATE_FORMAT(). Remember to consider time zones in your calculations for accurate results. This guide should help you efficiently work with dates in MySQL, particularly in retrieving and formatting yesterday’s date.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.