数据库日期类型为int
数据格式为
CreateTime
20120705
20120715
如何查询今日,昨日,本月,上月,今年,去年的数据
------解决方案--------------------------------------------------------
- SQL code
--今天select * from t where CreateTime=convert(varchar(8),getdate(),112);--昨天select * from t where CreateTime=convert(varchar(8),getdate()-1,112);--本月select * from t where substring(convert(varchar(8),CreateTime),1,6)=convert(varchar(6),getdate(),112);--上月select * from t where substring(convert(varchar(8),CreateTime),1,6)=convert(varchar(6),dateadd(m,-1,getdate()),112);--今年select * from t where substring(convert(varchar(8),CreateTime),1,4)=convert(varchar(4),getdate(),112);--去年select * from t where substring(convert(varchar(8),CreateTime),1,4)=convert(varchar(4),dateadd(year,-1,getdate()),112);