Comparing date values of CURDATE() with a full timestamp field

后端 未结 2 804
耶瑟儿~
耶瑟儿~ 2021-01-21 09:36

I have a function that is placing timestamp values (YYYY-MM-DD HH:MM:SS) into META_VALUE column of table META.

What I want to do is to compare

相关标签:
2条回答
  • 2021-01-21 09:52
    SELECT * FROM table WHERE <timestamp-field> BETWEEN 'YYYY-MM-DD 00:00:00' AND 'YYYY-MM-DD 23:59:59'
    

    Allways avoid doing calculations on the field if possible: e.g.

    SELECT * FROM table WHERE DATE(<timestamp-field>) = 'YYYY-MM-DD'
    

    will calculate DATE() for ALL rows in that table, so you are really talking wasted cycles here

    0 讨论(0)
  • 2021-01-21 09:59

    Simply use DATE:

    SELECT * FROM table WHERE DATE(timestamp) = '2011-12-29'
    
    0 讨论(0)
提交回复
热议问题