注册 登录
编程论坛 C# 论坛

关于c#日期查询问题

lukebc 发布于 2016-09-19 12:37, 2295 次点击
string time1 = rkrq1.Value.ToShortDateString();
string time2 = rkrq2.Value.ToShortDateString();
           
            if (time1.Trim() != "")
            {
                cond = cond + "and 日期>=" + time1;
            }
            if (time2.Trim() != "")
            {
                cond = cond + "and 日期>=" + time2;
            }
if (cond != "")
            {
                sql = "select * from rkb where 1=1  " + cond;
            }
            else
            {
                sql = "select * from rkb";
            }
2 回复
#2
ak1ca2016-10-27 10:06
1、用【between *and】但要注意时间范围,例如:select * from tb where riqi between '2009-01-22 00:00:00' and '2009-01-22 23:59:59'
2、用【convert()函数 】select * from tb where convert(varchar(10),riqi,120) = '2009-01-22'  
#3
zzqqrr2016-11-01 23:12
SQL拼接查询,要加上点如:'2016-1-12'
1