How do I query between two dates using MySQL?

前端 未结 10 2450
滥情空心
滥情空心 2020-11-22 00:58

The following query:

SELECT * FROM `objects` 
WHERE (date_field BETWEEN \'2010-09-29 10:15:55\' AND \'2010-01-30 14:15:55\')

returns nothin

10条回答
  •  庸人自扰
    2020-11-22 01:52

    You can do it manually, by comparing with greater than or equal and less than or equal.

     select * from table_name where created_at_column  >=   lower_date  and  created_at_column <= upper_date;
    

    In our example, we need to retrieve data from a particular day to day. We will compare from the beginning of the day to the latest second in another day.

      select * from table_name where created_at_column  >=   '2018-09-01 00:00:00'  and  created_at_column <= '2018-09-05 23:59:59';
    

提交回复
热议问题