SELECT * from table where DATEPART(month, 你的时间字段)<DATEPART(month, GETDATE())
declare @t table(date datetime) insert into @t(date) select '2011-12-20 11:22:22' union all select '2012-03-11 08:24:30' select year(date) as [年份],month(date) as [月份],datepart(month,date) as [月份1],convert(nvarchar(7),date,23) as [年月] from @t where convert(nvarchar(7),date,23) > '2011-12'
建议不要在列上用奇怪的函数。 比如需要查询2012年2月的文章那就是 时间 between 2012-2-1 0:0:0 and 2012-02-29 23:59:59
declare @t table(date datetime)
insert into @t(date) select '2011-12-20 11:22:22' union all select '2012-03-11 08:24:30'
select year(date) as [年份],month(date) as [月份],datepart(month,date) as [月份1],convert(nvarchar(7),date,23) as [年月]
from @t where convert(nvarchar(7),date,23) > '2011-12'
建议不要在列上用奇怪的函数。
比如需要查询2012年2月的文章那就是 时间 between 2012-2-1 0:0:0 and 2012-02-29 23:59:59