How to use an operator more with a date?

I don’t know what is going on here. Here is the request, directly from phpMyAdmin:

SELECT * FROM `la_schedule` WHERE 'start_date' >'2012-11-18'; 

But I consistently get all the records in the returned table, including those that are listed with the start date 2012-11-01. What gives?

+90
operators date mysql
Nov 19
source share
4 answers

You enlosed start_date with single quotes, forcing it to become a string, use backtick instead

 SELECT * FROM 'la_schedule' WHERE 'start_date' > '2012-11-18'; 
+163
Nov 19
source share

In your application, you are comparing a string called start_date with time.

If start_date is a column, it should be

 SELECT * FROM `la_schedule` WHERE start_date >'2012-11-18';
SELECT * FROM `la_schedule` WHERE start_date >'2012-11-18'; 

(without apostrophe) or

 SELECT * FROM `la_schedule` WHERE `start_date` >'2012-11-18';
SELECT * FROM `la_schedule` WHERE `start_date` >'2012-11-18'; 

(with backticks).



Hope this helps.

+21
Nov 19 '12 at 6:22
source share

Try it.

 SELECT * FROM la_schedule WHERE `start_date` > '2012-11-18'; 
+11
Nov 19 '12 at 8:11
source share

In my case, my column was a date and continued to give me all the entries. What I did to enable time, see the example below

 SELECT * FROM my_table where created_at > '2011-01-01 01:01:01' 
0
Jun 19 '19 at 9:22
source share



All Articles