CSP
CSP

Reputation: 49

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.

Upvotes: 4

Views: 11819

Answers (1)

Rishab Surana
Rishab Surana

Reputation: 2167

If you are doing this in postgresql then use

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

Upvotes: 2

Related Questions