sql server 2000关于日期的查询

在平时的开发中,经常会用到基于某个时间段的查询,比如选择开始日期、结束日期.(yyyy-MM-dd格式),而在数据库表中该列存储的格式却是(yyyy-MM-dd HH:MM:SS)格式,这样就要用到如下转换

sbSql.Append(string.Format(" AND Convert(Char(10),RegisterDate,120)<='{0}'", endRegisterDate));

 1 None.gif public  DataTable GetOvertureDocInfoList( string  boName,  int  isSend,  string  startRegisterDate,  string  endRegisterDate)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            try
 4ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 5InBlock.gif                string strSql = "SELECT * FROM GovInfo_OvertureDocument WHERE '1'='1' ";
 6InBlock.gif                StringBuilder sbSql = new StringBuilder(strSql);
 7InBlock.gif
 8InBlock.gif                if (isSend > -1)
 9ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
10InBlock.gif                    sbSql.Append(string.Format(" AND IsSend={0}",isSend));
11ExpandedSubBlockEnd.gif                }

12InBlock.gif
13InBlock.gif                if (startRegisterDate != "")
14ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
15InBlock.gif                    sbSql.Append(string.Format(" AND Convert(Char(10),RegisterDate,120)>='{0}'", startRegisterDate));
16ExpandedSubBlockEnd.gif                }

17InBlock.gif                if (endRegisterDate != "")
18ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
19InBlock.gif                    sbSql.Append(string.Format(" AND Convert(Char(10),RegisterDate,120)<='{0}'", endRegisterDate));
20ExpandedSubBlockEnd.gif                }

21InBlock.gif
22InBlock.gif                //if (status != "")
23InBlock.gif                //{
24InBlock.gif                //    sbSql.Append(string.Format("AND Status={0}", status));
25InBlock.gif                //}
26InBlock.gif
27InBlock.gif                sbSql.Append(" ORDER BY registerdate DESC");
28InBlock.gif
29InBlock.gif                SqlDBAccess dbaccess = new SqlDBAccess();
30InBlock.gif                DataSet ds = new DataSet();
31InBlock.gif                ds = dbaccess.ExecuteDataset(boName, CommandType.Text, sbSql.ToString());
32InBlock.gif                DataTable dt = ds.Tables[0];
33InBlock.gif
34InBlock.gif                return dt;
35ExpandedSubBlockEnd.gif            }

36InBlock.gif            catch (Exception e)
37ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
38InBlock.gif                LogUtil.Log.Error(this, e);
39InBlock.gif                throw e;
40ExpandedSubBlockEnd.gif            }

41ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/lae/archive/2006/05/10/395987.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值