MySQL select all rows from last month until (now() - 1 month), for comparative purposes

后端 未结 10 483
北海茫月
北海茫月 2020-12-07 18:12

I need some help writing a MySQL query to show me rows from last month, but not the whole month, only up and until the same day, hour and minute as it is now(), but 1 month

10条回答
  •  感情败类
    2020-12-07 19:12

    This is an example of a MySQL date operation relevant to your question:

    SELECT DATE_ADD( now( ) , INTERVAL -1 MONTH ) 
    

    The above will return date time one month ago

    So, you can use it, as follows:

    SELECT * 
    FROM your_table 
    WHERE Your_Date_Column BETWEEN '2011-01-04' 
        AND DATE_ADD(NOW( ), INTERVAL -1 MONTH )
    

提交回复
热议问题