开发者

MYSQL Datetime getting a date extract one month back

having a current date as 2011/12/05 .. , how to get a d开发者_C百科ate extract one month back ? 2011/11/05 ? in MYsql?


You can do this by adding condition to the WHERE:

created_at <= DATE_SUB(CURDATE(), INTERVAL 1 month)


select date_sub('2011-12-05',interval 1 month);


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜