MYSQL Datetime getting a date extract one month back

后端 未结 4 2003
别那么骄傲
别那么骄傲 2021-01-14 10:25

having a current date as 2011/12/05 .. , how to get a date extract one month back ? 2011/11/05 ? in MYsql?

相关标签:
4条回答
  • 2021-01-14 10:46

    You also can use

    SELECT * FROM tableName WHERE createdDate >= (now() - INTERVAL 1 MONTH);
    

    if you're looking for everything created in the last month.

    0 讨论(0)
  • 2021-01-14 10:47
    mysql> SELECT DATE_SUB(20111205, INTERVAL 1 MONTH);
    +--------------------------------------+
    | DATE_SUB(20111205, INTERVAL 1 MONTH) |
    +--------------------------------------+
    | 2011-11-05 |
    +--------------------------------------+
    1 row in set (0.88 sec) 
    

    FOR MORE INFO: Date-Arithmetic-With-MySQL

    0 讨论(0)
  • 2021-01-14 10:48
    select date_sub('2011-12-05',interval 1 month);
    
    0 讨论(0)
  • 2021-01-14 10:49

    You can do this by adding condition to the WHERE:

    created_at <= DATE_SUB(CURDATE(), INTERVAL 1 month)
    
    0 讨论(0)
提交回复
热议问题