--查最近一星期内的 select * from 表名 where 时间字段 between DATEADD(d, -7, getdate()) and getdate()
//这是用代码获取的最近一个星期的时间 string strTime=DateTime.Now.AddDays(Convert.ToInt32(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)) - 7).ToShortDateString(); string nowTime=DateTime.Now.ToShortDateString();select * from Test where Convert(datetime,testTime) between strTime and nowTime; //测试通过
select top 10 nid,ntitle,ncontent from t_news order by credate desc
例如去最近两天的:
获取当天的时间和前一天的时间sql:select * from t_news where date between 当前时间 and 前一天时间
//这是用代码获取的最近一个星期的时间
string strTime=DateTime.Now.AddDays(Convert.ToInt32(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)) - 7).ToShortDateString();
select * from 表名 where 时间字段 between DATEADD(d, -7, getdate()) and getdate()
//这是用代码获取的最近一个星期的时间
string strTime=DateTime.Now.AddDays(Convert.ToInt32(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)) - 7).ToShortDateString();
string nowTime=DateTime.Now.ToShortDateString();select * from Test where Convert(datetime,testTime) between strTime and nowTime;
//测试通过