the datediff truncate to the unit you are finding the diff over.
I will use floating point maths to make my point
Some time you expect the diff in "days" between 1.9 and 2.1 to be 0.2 days, but Snowflake will produce 1 because 2 is 1 more than 1.
It does this for every unit, second, hour, day, month.. to get a cleanly formatted duration like you might in PostgreSQL you have to roll your own functions.
select column1::timestamp as a
,column2::timestamp as b
,column3
,case column3
when 'second' then datediff('seconds', a, b)
when 'minute' then datediff('minute', a, b)
when 'hour' then datediff('hour', a, b)
when 'year' then datediff('year', a, b)
end as diff
,case column3
when 'second' then datediff('millisecond', a, b)/1000
when 'minute' then datediff('second', a, b)/60
when 'hour' then datediff('minute', a, b)/60
when 'year' then datediff('day', a, b)/365
end as f_diff
from values
('2022-09-12 13:16:59.999','2022-09-12 13:17:01.001', 'second'),
('2022-09-12 13:16:59','2022-09-12 13:17:01', 'minute'),
('2022-09-12 13:59:59','2022-09-12 14:03:01', 'hour'),
('2022-09-12 13:16:59','2023-01-12 13:17:01', 'year');
gives:
| A |
B |
COLUMN3 |
DIFF |
F_DIFF |
| 2022-09-12 13:16:59.999 |
2022-09-12 13:17:01.001 |
second |
2 |
1.002 |
| 2022-09-12 13:16:59.000 |
2022-09-12 13:17:01.000 |
minute |
1 |
0.033333 |
| 2022-09-12 13:59:59.000 |
2022-09-12 14:03:01.000 |
hour |
1 |
0.066667 |
| 2022-09-12 13:16:59.000 |
2023-01-12 13:17:01.000 |
year |
1 |
0.334247 |