SUB_DAYS
Description
The DATE_SUB function is used to calculate the date after subtracting a specified number of days from a given date. This is a very practical date calculation function that can help you easily handle date and time-related calculation issues.
Syntax
Parameters
startDate
: Start date, must use a valid date format (e.g., 'YYYY-MM-DD').numDays
: Number of days to subtract, must be an integer.
Return Result
Returns a new date representing the date after subtracting numDays
from startDate
. If the result exceeds the system's date range, it returns null.
Example
- Calculate the date 10 days before today:
- Calculate the date 3 days before May 31, 2020:
- Calculate the date 20 days before January 1, 2025:
- Calculate the date 5 days after December 31, 2023:
Precautions
- Ensure that the startDate parameter uses a valid date format, otherwise it may lead to inaccurate calculation results.
- If the calculation result exceeds the system's date range, the function will return null. Please ensure to handle this situation appropriately in actual applications.
By using the DATE_SUB function, you can easily perform date calculations, thereby better managing and analyzing data related to dates and times.