Filter by datetime MYSQL formatting

前端 未结 2 1307
抹茶落季
抹茶落季 2020-12-30 04:02

I have a Mysql Table that is used for a log file on the that table there is a field called \'log_date\' And it stores the date in the following format( %Y-%m-%d %H:%i.%s ).O

相关标签:
2条回答
  • 2020-12-30 04:43

    log_date should be of DateTime data type. It is much simpler to use MySQL DATE function. Some examples

    SELECT * FROM log_table
    WHERE DATE(log_date) < '2013-05-05'
    
    SELECT * FROM log_table
    WHERE DATE(log_date) > '2013-05-05'
    
    SELECT * FROM log_table
    WHERE DATE(log_date) BETWEEN '2013-04-05' AND '2013-05-05'
    
    SELECT * FROM log_table
    WHERE DATE(log_date) BETWEEN DATE(CURRENT_DATE() - INTERVAL 2 WEEK) AND 
    DATE(CURRENT_DATE() + INTERVAL 4 DAY)
    
    0 讨论(0)
  • 2020-12-30 04:46

    You can try with that..

      WHERE DATE_FORMAT(AUCTION_DATE, '%Y%m%d') >= DATE_FORMAT('2013/5/18', '%Y%m%d')
    

    You can also get today date using now() function.

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