MySQL selecting yesterday's date

后端 未结 8 595
猫巷女王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:57

    Last or next date, week, month & year calculation. It might be helpful for anyone.

    Current Date:

    select curdate();
    

    Yesterday:

    select subdate(curdate(), 1)
    

    Tomorrow:

    select affffdate(curdate(), 1)
    

    Last 1 week:

    select between subdate(curdate(), 7) and subdate(curdate(), 1)
    

    Next 1 week:

    between affffdate(curdate(), 7) and affffdate(curdate(), 1)
    

    Last 1 month:

    between subdate(curdate(), 30) and subdate(curdate(), 1)
    

    Next 1 month:

    between affffdate(curdate(), 30) and affffdate(curdate(), 1)
    

    Current month:

    subdate(curdate(),day(curdate())-1) and last_day(curdate());
    

    Last 1 year:

    between subdate(curdate(), 365) and subdate(curdate(), 1)
    

    Next 1 year:

    between affffdate(curdate(), 365) and affffdate(curdate(), 1)
    

提交回复
热议问题