标题:关于c#日期查询问题
只看楼主
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
 问题点数:0 回复次数:2 
关于c#日期查询问题
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";
            }
2016-09-19 12:37
ak1ca
Rank: 2
等 级:论坛游民
帖 子:3
专家分:20
注 册:2008-7-3
得分:0 
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'  
2016-10-27 10:06
zzqqrr
Rank: 6Rank: 6
来 自:299294817
等 级:侠之大者
威 望:1
帖 子:155
专家分:408
注 册:2011-6-11
得分:0 
SQL拼接查询,要加上点如:'2016-1-12'

59izk,com神奇百货,神奇百货网官网,shenqi,一个神奇的导购站!!
2016-11-01 23:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-468936-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.137843 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved