How to find thee difference in DAYS only when columns are in timestamp?

Viewed 49

I have two columns with timestamp. I am trying to find the difference in only DAYS ignoring the hours & minutes.

I am using SQL in Snowflake.

Ex :- I have both column values as following 
Column1 value = 07-DEC-16 11.05.24.500000000
Column2 value = 08-DEC-16 03.12.06.874000000

I would like to subtract the two columns for DAYS only, in this example since Dec 8-Dec 7 =1

1 Answers

Using DATEDIFF/TIMESTAMPDIFF:

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

SELECT DATEDIFF(day, col1, col2)
FROM tab;

or:

SELECT ABS(DATEDIFF(day, col1, col2)) -- absolute value
FROM tab;
Related