How to use greater than operator with date?

前端 未结 6 1689
鱼传尺愫
鱼传尺愫 2020-12-05 03:36

No idea what is going on here. Here is the query, right from phpMyAdmin:

SELECT * FROM `la_schedule` WHERE \'start_date\' >\'2012-11-18\';
相关标签:
6条回答
  • 2020-12-05 04:05

    Adding this since this was not mentioned.

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

    Because that's what actually works for me. Adding date() function on both comparison values.

    0 讨论(0)
  • 2020-12-05 04:06

    In your statement, you are comparing a string called start_date with the time.
    If start_date is a column, it should either be

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

    (no apostrophe) or

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

    (with backticks).

    Hope this helps.

    0 讨论(0)
  • 2020-12-05 04:09

    I have tried but above not working after research found below the solution.

    SELECT * FROM my_table where DATE(start_date) > '2011-01-01';
    

    Ref

    0 讨论(0)
  • 2020-12-05 04:10

    In my case my column was a datetime it kept giving me all records. What I did is to include time, see below example

    SELECT * FROM my_table where start_date > '2011-01-01 01:01:01';
    
    0 讨论(0)
  • 2020-12-05 04:19

    Try this.

    SELECT * FROM la_schedule WHERE `start_date` > '2012-11-18';
    
    0 讨论(0)
  • 2020-12-05 04:20

    you have enlosed start_date with single quote causing it to become string, use backtick instead

    SELECT * FROM `la_schedule` WHERE `start_date` > '2012-11-18';
    
    • SQLFiddle Demo
    0 讨论(0)
提交回复
热议问题