Reputation: 1552
I need to select only the year from the record date.
SELECT *, DATE_FORMAT('release','%Y') AS release_year FROM books
but doesnt work. The result in phpmyadmin is NULL.
Upvotes: 1
Views: 7417
Reputation: 1313
Your problem :
DATE_FORMAT('release','%Y')
in Mysql that is a string.
Fix :
SELECT *, DATE_FORMAT(`release`,'%Y') AS release_year FROM books;
Upvotes: 1
Reputation: 562320
Don't put release
in quotes. You're trying to extract the year from a literal string 'release'
, not the value in the column `release
`.
And as @invisal states, RELEASE is a reserved word in MySQL, so you have to delimit it with back-ticks.
Upvotes: 2
Reputation: 11171
SELECT *, YEAR(`release`) AS release_year FROM books
I think release
is a MySQL keyword. Try to wrap it around ``
Upvotes: 6