Reputation: 69
I have a form with a text field, where the user will provide the year only and MySQL data should return all the data for the given year. But in MySQL database, the date
is given in date(yyyy-mm-dd)
format.
Can anyone suggest the SQL query which will fetch all the data for that particular year?
Upvotes: 3
Views: 149
Reputation: 1455
try this one, use the MySQL YEAR
function.
SELECT *
FROM tableName
WHERE YEAR(dateCOlumn) = 2012
so in the given example, the server will select all records where year is equal to 2012.
UPDATE 1
Upvotes: 5
Reputation: 4221
Try
select * from tablename where year(columname) = 'whatever the year is';
Hope this helps.
Upvotes: 0