当前位置: 代码迷 >> ASP.NET >> 文章归档,该怎么解决
  详细解决方案

文章归档,该怎么解决

热度:715   发布时间:2013-02-25 00:00:00.0
文章归档
我想实现一个文章归档功能,就是比如2012年2月的文章点进去就从数据库读取相应的文章列表,我现在数据的类型是DATETIME的就是年月日分秒,我只想读取几月份的这个代码怎么写?

------解决方案--------------------------------------------------------
SQL语句,SELECT DATEPART(month, GETDATE())//读取今天的月份
------解决方案--------------------------------------------------------
SELECT * from table where DATEPART(month, 你的时间字段)<DATEPART(month, GETDATE())
------解决方案--------------------------------------------------------
SQL code
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月的文章点进去就从数据库读取相应的文章列表


------解决方案--------------------------------------------------------
探讨
SELECT * from table where DATEPART(month, 你的时间字段)<DATEPART(month, GETDATE())
  相关解决方案