Description
Returns the difference between two dates or timestamps
Aliases: DATE_DIFF
Syntax
DATEDIFF(unit, start, end)
Parameters
| Parameter | Description | Data Type | Required |
|---|---|---|---|
| unit | Date part for the difference (for example day, week, month, year) | String | Yes |
| start | Starting date or timestamp | Date or timestamp | Yes |
| end | Ending date or timestamp | Date or timestamp | Yes |
Accepted datepart values
| Datepart Name | Datepart Abbreviation |
|---|---|
| year | yy, yyyy |
| quarter | qq, q |
| month | mm, m |
| dayofyear | dy, y |
| day | dd, d |
| week | wk, ww |
| weekday | dw, w |
| hour | hh |
| minute | mi, n |
| second | ss, s |
| millisecond | ms |
| microsecond | mcs |
| nanosecond | ns |
Notes
- Public Transformations SQL spelling is
DATEDIFF(...).DATE_DIFF(...)is also accepted by the parser.
Example
SELECT
DATEDIFF('day', start_date, end_date)
FROM
rippling.employee.Employee
LIMIT
5;