BradM
BradM

Reputation: 656

PHP - mysqli_query - WHERE and date

I have a PHP query that I only want to select if the date is 2014 in the table:

$result=mysqli_query($linkID, "SELECT * FROM table WHERE date(Y) = '2014'";

I'm trying to call "date(Y)" with the correct expression as that is obviously incorrect.

Upvotes: 0

Views: 544

Answers (2)

takeit
takeit

Reputation: 4081

Use this:

$result=mysqli_query($linkID, "SELECT * FROM table WHERE YEAR(datetime_field) = 2014");

Upvotes: 0

Paolo
Paolo

Reputation: 15827

the query should be

SELECT * FROM table WHERE YEAR(the_date_field) = 2014

the_date_field is the field containing the date of course

Upvotes: 1

Related Questions