Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

datediff

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.

like image 382
CSP Avatar asked Mar 03 '26 11:03

CSP


1 Answers

If you are doing this in postgresql then use

select DATE_PART('day', '2014-01-01'::timestamp -  '2014-02-01'::timestamp)
like image 137
Rishab Surana Avatar answered Mar 06 '26 02:03

Rishab Surana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!