我在数据库中有两列,project_start 和 project_end,我正在通过报告(用 ASP 编码)传递两个字段(都是可选的)。
下面的伪代码是我目前拥有的:
(project_start <= search_start AND project_end <= search_start)
和
(project_start <= search_end AND project_end >= search_end)
但是,上面没有提到的是在开始日期之前开始但在开始日期之后结束的项目,在开始日期之后开始但在结束日期之后结束的项目,以及在开始日期之前开始并结束的项目结束日期之后:S
下面是我的代码:
if (Request.QueryString["DateFrom"] != null && Request.QueryString["DateFrom"] != "")
{
DateTime dateFromFilter;
dateFromFilter = DateTime.Parse(Request.QueryString["DateFrom"]);
Q = from qua in qTable
where qua.Start_Date.Date <= dateFromFilter.Date
&& qua.End_Date.Date >= dateFromFilter.Date
select qua;
}
//filter to date
if (Request.QueryString["DateTo"] != null && Request.QueryString["DateTo"] != "")
{
DateTime dateToFilter;
dateToFilter = DateTime.Parse(Request.QueryString["DateTo"]);
Q= from qua in qTable
where qua.Start_Date.Date <= dateToFilter.Date
&& qua.End_Date.Date >= dateToFilter.Date
select qua;
}