我正在尝试编写一个实体框架查询来查找日期之间的差距。我无法理解它。下面是数据的样子,我想找到差距,当我通过一组日期。
预期结果1
Start Date - 2021-01-01
End Date - 2021-01-31
Result : null
预期结果2
End Date - 2021-02-28
Result : [
{
startDate : 2021-02-06
endDate : 2021-02-09
},
{
startDate : 2021-02-13
endDate : 2021-02-28
}
]
有谁能帮我做这件事吗?
使用C#可以计算两次之间的时间,这称为时间跨度,并且可以提取一些字段:
DateTime fromDate = new DateTime(2020, 12, 01);
DateTime toDate = new DateTime(2021, 02, 05);
TimeSpan ts = toDate - fromDate;
string Msg = $"Between {fromDate} and {toDate} are {ts.TotalDays} days";