sql="select **** from *** where 条件 ";
sql += string.Format("and Date >='{0}'", dateTimePicker_low.Value.ToShortDateString());
sql += string.Format("and Date <='{0}'", dateTimePicker_high.Value.ToShortDateString());
下面执行一下sql语句把结果返回就行了。
dateTimePicker_low,dateTimePicker_high是两个dateTimePicker控件。用于选择时间
是从数据库里查询吗?
如果是的话:
string stime = this.txt_stime.Text == "" ? "1900-01-01" : this.txt_stime.Text;//开始时间
string etime = this.txt_etime.Text == "" ? "9999-01-01" : this.txt_etime.Text;//结束时间
if (Convert.ToDateTime(stime) <= Convert.ToDateTime(etime))
{
if (stime.Equals("1900-01-01") && etime.Equals("9999-01-01"))
{
}
else
{
strWhere.Append(" AND convert(varchar(10),数据库中保存时间的字段,120) between '" + stime + "' AND '" + etime + "'");
}
}
else
{
WebScript.Alert(this, "开始时间不能大于结束时间!");
}
select * from table where datateme between begintime and endtime
DateTime.Compare(DateTime1,DateTime2)
或者年月日时分秒挨个比较