Mysql Compare two datetime fields

后端 未结 4 704
花落未央
花落未央 2020-12-02 10:08

I want to compare two dates with time, I want all the results from tbl where date1 > date2

Select * From temp where mydate > \'2009-06-29          


        
4条回答
  •  伪装坚强ぢ
    2020-12-02 10:30

    The query you want to show as an example is:

    SELECT * FROM temp WHERE mydate > '2009-06-29 16:00:44';
    

    04:00:00 is 4AM, so all the results you're displaying come after that, which is correct.

    If you want to show everything after 4PM, you need to use the correct (24hr) notation in your query.

    To make things a bit clearer, try this:

    SELECT mydate, DATE_FORMAT(mydate, '%r') FROM temp;
    

    That will show you the date, and its 12hr time.

提交回复
热议问题