按日期选择 [英] datewise selection

查看:123
本文介绍了按日期选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的代码有疑问.我使用以下代码从查询中选择一个日期到另一个日期的数据.在运行时,它将显示日期和时间,但我只想要日期.我该如何清除?我编码为:


字符串s1;
TimeSpan时间=新的TimeSpan(0,00,10); //3小时30分钟
s1 =(dateTimePicker1.Value.Date + time).ToString();
select * FROM credit WHERE date< =((SELECT DATEADD(hh,-(SELECT DATEDIFF(hh,''"+ s1 +"'',''"+ dateTimePicker2.Value +"'')),''"+ dateTimePicker2 .Value +''))"

有人可以帮我吗?

I have a doubt in my code. I use the following code to select data from one date to another date, from my query. On running, it will display the date and time but i want the date only. How can I clear this? I coded as:


string s1;
TimeSpan time = new TimeSpan(0, 00, 10); // 3 hours and 30 minutes
s1 = (dateTimePicker1.Value.Date + time).ToString();
select * FROM credit WHERE date<=(SELECT DATEADD(hh,-(SELECT DATEDIFF(hh,''" + s1 + "'',''" + dateTimePicker2.Value + "'')), ''" + dateTimePicker2.Value + "'')) "

Can anybody help me?

推荐答案

您做了什么调试工作?构造后的SQL语句是什么样的? (顺便说一句,使用string.format将使其更具可读性)我们无法从变量中分辨出来.

TimeSan(0,00,10)不等于3小时30分钟.等于10秒.
What have you done to debug this? What does the SQL statement look like after it has been constructed? (BTW, using string.format would make it more readable) We can''t tell from the variables.

TimeSan(0, 00, 10) Does not equal 3 hours and 30 minutes. It equals 10 seconds.


这篇关于按日期选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆