MySQL
SQL Functions
Date Manipulation
Database Management
Coding Tips
MySQL's now 1 day
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To add or subtract one day from the current date and time in MySQL, use NOW() + INTERVAL 1 DAY or DATE_ADD(NOW(), INTERVAL 1 DAY). To subtract, use NOW() - INTERVAL 1 DAY or DATE_SUB(NOW(), INTERVAL 1 DAY). Both syntaxes produce the same result. NOW() returns the current date and time as a DATETIME value, and INTERVAL arithmetic preserves the time component. For date-only results, use CURDATE() instead of NOW().
Adding One Day to NOW()
Subtracting One Day from NOW()
Other Interval Units
Practical Use Cases
NOW() vs CURDATE() vs CURRENT_TIMESTAMP
Date Difference Calculations
Using in WHERE Clauses with Indexes
Common Pitfalls
- Wrapping a column in
DATE()prevents index usage:WHERE DATE(created_at) = CURDATE()forces a full table scan because MySQL cannot use the index oncreated_atthrough a function. Instead, use a range:WHERE created_at >= CURDATE() AND created_at < CURDATE() + INTERVAL 1 DAY. - Confusing
NOW()withCURDATE()in interval arithmetic:NOW() + INTERVAL 1 DAYreturns a DATETIME with the time preserved.CURDATE() + INTERVAL 1 DAYreturns a DATE with no time component. Using the wrong one in comparisons can include or exclude records near midnight boundaries. - Timezone inconsistencies between
NOW()andUTC_TIMESTAMP():NOW()returns the server's local time, which depends on thetime_zonesession variable. If your application stores timestamps in UTC but queries withNOW()in a non-UTC timezone, you get incorrect results. UseUTC_TIMESTAMP()or set the session timezone to UTC. - Using
INTERVAL 1 MONTHnear month boundaries:'2025-01-31' + INTERVAL 1 MONTHreturns'2025-02-28', not March 3rd. MySQL clamps to the last valid day of the target month. Subtracting a month from the result does not return the original date:'2025-02-28' - INTERVAL 1 MONTHgives'2025-01-28', not January 31st. NOW()returning the same value within a single statement: In a stored procedure or trigger, all references toNOW()within a single statement return the same value (statement start time). UseSYSDATE()if you need the actual clock time at each evaluation point, but be aware thatSYSDATE()is not replication-safe.
Summary
- Use
NOW() + INTERVAL 1 DAYorDATE_ADD(NOW(), INTERVAL 1 DAY)to add one day - Use
NOW() - INTERVAL 1 DAYorDATE_SUB(NOW(), INTERVAL 1 DAY)to subtract one day - Use
CURDATE()for date-only calculations,NOW()when the time component matters - Avoid wrapping indexed columns in functions like
DATE()— use range comparisons instead - Be aware of timezone differences between
NOW()(local) andUTC_TIMESTAMP()(UTC)

