DAY identifies the day component of a date or timestamp value. SQL engines expose it in two main contexts:1. Interval literals – INTERVAL 'n' DAY adds or subtracts whole days.2. Date-time functions – EXTRACT(DAY FROM ts) returns the numeric day of the month; DATEADD(DAY, n, date) shifts a date forward or backward by n days; DATEDIFF(DAY, date1, date2) calculates the number of days between two dates.Standard SQL also allows specifying DAY with higher-precision fields (DAY TO SECOND) to create complex intervals. Because DAY is language-reserved, it cannot be used as an unquoted column or table name without delimiters. Most engines treat DAY as case-insensitive.Caveats:- Some dialects (SQLite, MySQL) use alternative functions instead of DATEADD/DATEDIFF.- INTERVAL syntax varies: PostgreSQL follows the SQL standard, while SQL Server and MySQL require keywords like DAY following an interval expression or DATEADD.- When extracting DAY, remember that the result is the calendar day of month (1-31), not the day of week.
SQL-92 (temporal data and INTERVAL types)
DAY returns the calendar day 1-31. DOW (or equivalent) returns 0-6 for Sunday-Saturday.
Use DATEDIFF(DAY, start_date, end_date) in T-SQL or end_date - start_date in PostgreSQL. Both yield the day count.
Yes. SQL supports composite intervals like INTERVAL '3 04:00' DAY TO HOUR, representing 3 days and 4 hours.
No. SQL keywords are case-insensitive, so DAY, Day, and day behave the same.