A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/timediff below:

Website Navigation


TIMEDIFF | Snowflake Documentation

Categories:

Date & time functions

TIMEDIFF

Calculates the difference between two date, time, or timestamp expressions based on the specified date or time part. The function returns the result of subtracting the second argument from the third argument.

Alternative for DATEDIFF.

Syntax
TIMEDIFF( <date_or_time_part> , <date_or_time_expr1> , <date_or time_expr2> )

Copy

Arguments
date_or_time_part

The unit of time. Must be one of the values listed in Supported date and time parts (for example, month). The value can be a string literal or can be unquoted (for example, 'month' or month).

date_or_time_expr1, date_or_time_expr2

The values to compare. Must be a date, a time, a timestamp, or an expression that can be evaluated to a date, a time, or a timestamp. The value date_or_time_expr1 is subtracted from date_or_time_expr2.

Returns

Returns an integer representing the number of units (seconds, days, etc.) difference between date_or_time_expr2 and date_or_time_expr1.

Usage notes Examples

This shows the result of subtracting two dates, in which the second is two years later than the first:

SELECT TIMEDIFF(YEAR, '2017-01-01', '2019-01-01') AS Years;
+-------+
| YEARS |
|-------|
|     2 |
+-------+

Copy

This shows that the value is truncated rather than rounded. The difference is closer to 12 months than to 11, but Snowflake calculates the difference as 11 months:

SELECT TIMEDIFF(MONTH, '2017-01-1', '2017-12-31') AS Months;
+--------+
| MONTHS |
|--------|
|     11 |
+--------+

Copy

There are additional examples in DATEDIFF.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4