Snowflake simplifies the process of calculating the difference between dates and performing date arithmetic, such as adding or subtracting time intervals from specific dates.
To calculate the difference between two dates, you can utilize the DATEDIFF function. The format of the function is as follows:
DATEDIFF( <date_or_time_part>, <date_or_time_expr1>, <date_or_time_expr2> )
An example and real-world use case would be measuring the difference in days from lead creation to conversion.
DATEDIFF('days', "CreatedDate", "ConvertedDate") AS "Lead Create to Convert Days"
You can calculate the diff between date and date times using the following date time parts:
- year
- month
- day
- week
- quarter
- hour
- minute
- second
- Millisecond