Select data between a date/time range

后端 未结 8 1620
迷失自我
迷失自我 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;

    0 讨论(0)
  • 2020-11-27 15:30

    Here is a simple way using the date function:

    select *
    from hockey_stats
    where date(game_date) between date('2012-11-03') and date('2012-11-05')
    order by game_date desc
    
    0 讨论(0)
提交回复
热议问题