查询时间范围
查一个表的 time 字段 时间范围是最近7天
string sql="select * from table1 time between to_date('" + DateTime.Now.AddDays(-7).ToString() + "','yyyy-mm-dd HH24:mi:ss') AND to_date('" + DateTime.Now.ToString() + "','yyyy-mm-dd HH24:mi:ss')";
如果最近几周应该怎么写
------解决方案--------------------+ DateTime.Now.AddDays(-7*周数-(int)DateTime.Now.DayOfWeek).ToString() +
------解决方案--------------------用得着这么复杂吗?
string sql="select * from table1 Where datediff(dd,[time],getdate())<=7
以上是获取7天内的数据
------解决方案--------------------1、string sql="select * from table1 where time between to_date('2013-01-01','yyyy-mm-dd HH24:mi:ss') AND to_date('2013-12-31 23:59:59','yyyy-mm-dd HH24:mi:ss')";
2、string sql="select * from table1 where to_char(time,'yyyy')=2013";