'DATEDIFF command won't work as 'day' is not a recognised column

I'm relatively new to SQL and have been attempting to run a script wherein I can bring up the number of days that have passed between two points in time. I understand how this should look based on your website, but for some reason when I input the values, my database is returning the following error:

ProgrammingError: ERROR: column "day" does not exist

The code I'm using is:

select datediff(day, '2014-01-01', '2014-02-01')

I assume I'm missing something very simple (this is a hugely basic query I'm sure), but would be appreciative of any assistance. I've variously tried pointing it towards the specific table I want to draw from, but it keeps stumbling on this error.



Solution 1:[1]

If you are doing this in postgresql then use

select DATE_PART('day', '2014-01-01'::timestamp -  '2014-02-01'::timestamp)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rishab Surana