popkutt
popkutt

Reputation: 1029

MySQL NOW() query

SELECT * FROM ps_specific_price WHERE 'to' > NOW() ORDER BY `to` DESC

or

 SELECT * FROM ps_specific_price WHERE 'to' > CURDATE() ORDER BY `to` DESC

The date in the 'to' field are like this: 2014-07-31 23:59:59

There is only one row where the 'to' is larger than now() but anyway the query returns the entire table (all the 1287 rows of the table). Where did I go wrong with theses queries?

Upvotes: 0

Views: 75

Answers (3)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111889

You should use:

SELECT * FROM ps_specific_price WHERE `to` > NOW() ORDER BY `to` DESC

using backticks and not quotes

Upvotes: 4

Bahrami-Reza
Bahrami-Reza

Reputation: 608

you can use :

  SELECT * FROM ps_specific_price WHERE DATE(to) = DATE(NOW()) ORDER BY to DESC

Upvotes: 1

Muhammad Ali
Muhammad Ali

Reputation: 2014

you have used wrong quotation ,, you need to use grave accent (`) grave accent is use for mysql field and table

SELECT * FROM `ps_specific_price` WHERE `to` > CURDATE() ORDER BY to DESC

Upvotes: 1

Related Questions