Select data between a date/time range

后端 未结 8 1791
迷失自我
迷失自我 2020-11-27 14:43

How do I select data between a date range in MySQL. My datetime column is in 24-hour zulu time format.

select * from hockey_stats 
where game_d         


        
8条回答
  •  清酒与你
    2020-11-27 15:29

    You can either user STR_TO_DATE function and pass your own date parameters based on the format you have posted :

    select * from hockey_stats where game_date 
      between STR_TO_DATE('11/3/2012 00:00:00', '%c/%e/%Y %H:%i:%s')
      and STR_TO_DATE('11/5/2012 23:59:00', '%c/%e/%Y %H:%i:%s') 
    order by game_date desc;
    

    Or just use the format which MySQL handles dates YYYY:MM:DD HH:mm:SS and have the query as

    select * from hockey_stats where game_date between '2012-03-11 00:00:00' and'2012-05-11 23:59:00' order by game_date desc;

提交回复
热议问题