SQL includes useful functions to work with dates and times.
DATEADD(unit, number, date)
— Adds a specified number of units (days, months, years) to a dateDATEDIFF(unit, start_date, end_date)
— Calculates the difference between two dates in specified unitsEXTRACT(part FROM date)
— Extracts part of a date like year, month, or daySELECT * FROM students
WHERE DATEDIFF(day, join_date, CURRENT_DATE) > 30;
This finds students whose join_date
is more than 30 days before today.
Date functions help analyze timelines, calculate ages, filter date ranges, and more.