在LINQ查询两个日期之间的日期范围下降 [英] Date range falling between two dates in a LINQ query

查看:1048
本文介绍了在LINQ查询两个日期之间的日期范围下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写它返回,其中输入的日期范围落在LINQ查询两个日期字段之间的记录选择查询



我的输入是:




  • DATE1 - 开始日期

  • date2的 - 结束日期



我的数据库字段是




  • AppointmentStart

  • AppointmentEnd



此外,我也想确保14:00输入 - 15:00不返回。15值:00-16:中db.Appointments 00

 收益率(从T1其中(t1.AppointmentStart< = DATE2&功放;及(t1.AppointmentEnd)> = DATE1)

如果有人能帮助我这一点,我会很感激的。


解决方案

看起来向后我。



如果满足以下条件:



日期1 =启动



日期2 =结束



 <$:

那我就等于appointmentstart之前结束日期或等于appointmentend或之后开始日期思考C $ C>收益率(从db.Appointments哪里(日期1> T1 = t1.AppointmentStart和放大器;&安培; DATE2< = t1.AppointmentEnd))



我也改变了括号,因为他们没有任何意义我(似乎是一人失踪)


I'm trying to write a select query which returns records where the input date range falls between two date fields in a LINQ query.

My inputs are:

  • date1 - start date
  • date2 - end date

My database fields are

  • AppointmentStart
  • AppointmentEnd

Additionally, I'd also like to ensure that an input of 14:00 - 15:00 doesn't return a value for 15:00-16:00.

return (from t1 in db.Appointments where (t1.AppointmentStart <= date2 && (t1.AppointmentEnd) >= date1)

If anybody can assist me with this, I'd appreciate it.

解决方案

It looks backwards to me.

if the following is true:

Date1 = start

Date2 = end

then i would think startdate after or equal to appointmentstart and enddate before or equal to appointmentend or:

return (from t1 in db.Appointments where (date1 >= t1.AppointmentStart && date2 <= t1.AppointmentEnd))

i also changed the parens because they didn't make sense to me (seemed like one was missing)

这篇关于在LINQ查询两个日期之间的日期范围下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆