SQL数据库中记录日期格式的数据如 ‘2012-8-13 00:00:00’假如1小时一条数据 一天24小时 怎么提取当天的数据?select * from rec_pm where date = CONVERT(varchar(100), GETDATE(), 23)为什么没有数据啊?
解决方案 »
- web留言板怎么实现隔行换色~!?
- 为什么我这个backgroundWorker1里的方法不执行
- VS2008调试,没有为该文档加载任何符号
- C#调试问题 显示出的SQL语句
- 新手求教:C#串口读数据
- 错误提示:找不到存储过程,问题是存储过程有啊~
- c#winfrom 控件设计时支持的问题
- C#生成创建文件,flash读乱码,必须用记事本打开,保存存一下就OK,请解决。
- 请问我在C#中怎么调用水晶报表,我的水晶报表是11的
- 我在DataGrid1的属性Columns--->列---->超级连接列里面点某个值时,,是否可以得到这个值?
- 无法访问已释放的对象 对象名:Icon
- xhEditor谁使用过?求助!!预览功能实现
比较“年-月-日”相等就可以了,如下
select *
from rec_pm
where CONVERT(varchar(12) ,date , 111 )=CONVERT(varchar(12) , getdate(), 111 )
string kssj =dateTimePicker1.Value.ToString().Substring(0,dateTimePicker1.Value.ToString().IndexOf(" ")) + " 00:00:00";
string jssj = dateTimePicker2.Value.ToString().Substring(0, dateTimePicker2.Value.ToString().IndexOf(" ")) + " 23:59:59";以上字符我是获取当天的日期然后将时间转换一下,比如当天日期是2012-8-10,我加上时间变成2012-8-10 00:00:00,和结束时间2012-8-10 23:59:59
然后用查询语句,假设你时间的字段名就叫“时间”
select * from rec_pm where date 时间>=kssj and 时间<=jssj
你试试吧,有问题再交流
SELECT
SUBSTRING(CONVERT(VARCHAR,date,120),0,14) AS '时间',
COUNT(1) AS '数量'
from rec_pm
where CONVERT(varchar(12) ,date , 111 )=CONVERT(varchar(12) , getdate(), 111 )
GROUP BY
SUBSTRING(CONVERT(VARCHAR,date,120),0,14)
查询当天的记录
select * from tableName where DATEPART(dd, theDate)=DATEPART(dd, GETDATE()) and
DATEPART(mm, theDate)=DATEPART(mm, GETDATE()) and
DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
查询本月的记录
select * from tableName where DATEPART(mm, theDate)=DATEPART(mm, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
查询本周的记录
select * from tableName where DATEPART(wk, theDate) = DATEPART(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
查询本季的记录 注:其中:GETDATE()是获得系统时间的函数。
select * from tableName where DATEPART(qq, theDate) = DATEPART(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
select datepart(hh,date)
,count(1) 分小时数量
--如果有求和的,此处加sum(求和列)
from rec_pm
where convert(varchar(8),date,112 )=convert(varchar(8),getdate(),112)
group by datepart(hh,date)
sql += " [CommTime] between '" + st + "'and '" + et + "'";
其中st和et是起始时间跟截止时间