mysql上个月日期声明 [英] mysql last month date statement
本文介绍了mysql上个月日期声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日期,我该如何写一个where
来检查直到现在的上个月(-1月的第一天还是今天的第一个月)?
I have a DATE, how do I write a where
that checks for last month until now (either the first of or just today's day -1 month)?
推荐答案
SELECT * FROM table WHERE dateField > DATE_SUB(NOW(), INTERVAL 1 MONTH)
这将选择所有具有dateField
的当前时间比当前时间戳减去一个月最近的行(因此,例如,假设今天是2009年9月26日00:56,它将给出比2009年8月26日更新的行: 56)
This selects all rows that have a dateField
more recent than current timestamp minus one month (so, for example, given today is 26 Sep 2009 00:56 it would give rows that are more recent than 26 Aug 2009 00:56)
这篇关于mysql上个月日期声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文