MySQL How to SELECT data from table which recorded today?

前端 未结 8 1762
死守一世寂寞
死守一世寂寞 2021-02-04 04:35

Use PHP and MySQL. In my table, there is date field (datetime) recorded by NOW() sql function. Example value of data in this field is 2010-10-07 10:57:36. Ho

相关标签:
8条回答
  • 2021-02-04 04:45
    SELECT * FROM tableName WHERE DATE(fieldDate) = DATE(NOW());
    
    0 讨论(0)
  • 2021-02-04 04:50

    SELECT * FROM table where DATE(date)=CURDATE()

    0 讨论(0)
  • 2021-02-04 04:51

    use between.

    select * from table date between '2010-10-06' and '2010-10-08';
    
    0 讨论(0)
  • 2021-02-04 04:53
    SET @day = '2017-12-12' ;
    
    SELECT * FROM table WHERE dateColumn BETWEEN DATE(@day) AND DATE_ADD(DATE(@day), INTERVAL 1 DAY ) ;
    
    0 讨论(0)
  • 2021-02-04 05:01

    use something like this it exactly works on my code(access database):

    select * from Table t where t.column>=Date() and t.column< Date() + 1
    
    0 讨论(0)
  • 2021-02-04 05:04

    The date_format function allows you to easily switch between various granularities:

    Select everything from the same day:

    select * from table 
    where date_format(date, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d');
    

    From the same month:

    select * from table 
    where date_format(date, '%Y-%m') = date_format(now(), '%Y-%m');
    

    From the same year:

    select * from table 
    where date_format(date, '%Y') = date_format(now(), '%Y');
    

    From the same hour:

    select * from table 
    where date_format(date, '%Y-%m-%d %H') = date_format(now(), '%Y-%m-%d %H');
    

    and so on.

    0 讨论(0)
提交回复
热议问题