MySQL selecting yesterday's date

后端 未结 8 588
猫巷女王i
猫巷女王i 2020-12-02 10:08

How can I display and count the values whose dates are yesterday? I used time() to insert date in the database. Example:

URL: google.com youtube         


        
8条回答
  •  旧巷少年郎
    2020-12-02 10:48

    I adapted one of the above answers from cdhowie as I could not get it to work. This seems to work for me. I suspect it's also possible to do this with the UNIX_TIMESTAMP function been used.

    SELECT * FROM your_table
    
    WHERE UNIX_TIMESTAMP(DateVisited) >= UNIX_TIMESTAMP(CAST(NOW() - INTERVAL 1 DAY AS DATE))
      AND UNIX_TIMESTAMP(DateVisited) <= UNIX_TIMESTAMP(CAST(NOW() AS DATE));
    

提交回复
热议问题