您现在的位置:首页 >> 软件开发 >> 内容

C# WinForm中使用SQL指令查找某日期时间段的方法

时间:2023-12-12 23:13:44 点击:

  核心提示:日期+时间段查换,SQL SERVER数据库,见下图:叁考代码:edate.Text = System.DateTime.Now.ToShortDateString();bdate.Text = Co...

日期+时间段查换,SQL SERVER数据库,见下图:





叁考代码:


edate.Text = System.DateTime.Now.ToShortDateString();
bdate.Text = Convert.ToDateTime(edate.Text).AddDays(-0).ToShortDateString();


strsql = "select top 1500 * from qbdj_dljl where (CONVERT(CHAR(10),jldate,121)>='" + bdate.Text + "' or '" + bdate.Text + "'='' ) and (CONVERT(CHAR(10),jldate,121)<='" + edate.Text + "' or '" + edate.Text + "'='' ) ";


 


还有另一种方法:


edate.Text = System.DateTime.Now.ToShortDateString();
bdate.Text = Convert.ToDateTime(edate.Text).AddDays(0).ToShortDateString();


//结束时间多增加1天,解决查询不到结束当天记录问题
string bd = string.Format("{0:d}", bdate.Text);
string ed = string.Format("{0:d}", edate.Text);
ed = Convert.ToDateTime(ed).AddDays(1).ToShortDateString();


strsql = "select top 1000 * from dljl where (CONVERT(datetime, jldate)>='" + bd + "' or '" + bd + "'='' ) and (CONVERT(datetime, jldate)<='" + ed + "' or '" + ed + "'='' ) ";

作者:站长 来源:原创
相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 陈工笔记(www.dui580.com) © 2024 版权所有 All Rights Reserved.
  • 站长:陈工 微信号:chengongbiji QQ:24498854
  • Powered by 陈工