选择两个日期之间的所有数据 [英] Selection of all data between two dates

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

问题描述

Hellow everyone!



我有一个LINQ查询问题,我没有看到问题。



案例:



我必须选择2个日期之间的所有约会。 (ex 21/04/2014 8:00 to 23/04/2014 12:00)



我应该可以查询4种类型的约会

nr 1:2014年4月19日至2014年4月22日的预约(开始于选择之前,在选择之内结束)

nr2:从2014年4月22日开始预约2014年4月22日(开始在选择范围内并在选择范围内结束)

nr3:从2014年4月22日到2014年4月25日的预约(开始在选择范围内并在选择后结束)

nr4:2014年4月19日至2014年4月24日的预约(开始时间选择之前,选择后结束)



(我希望这有道理......并且可以理解)



此刻我有以下查询



Hellow everyone!

I have a problem with a LINQ query and I don't see the problem.

The Case:

I have to select all appointments between 2 dates. (ex 21/04/2014 8:00 to 23/04/2014 12:00)

I should be possible to query 4 types of appointments
nr 1: an appointment from 19/04/2014 to 22/04/2014 (start is before selection and ends within selection)
nr2: an appointment from 22/04/2014 to 22/04/2014 (start is within selection and ends within selection)
nr3: an appointment from 22/04/2014 to 25/04/2014 (start is within selection and ends after selection)
nr4: an appointment from 19/04/2014 to 24/04/2014 (start is before selection and ends after selection)

(I hope this makes sense... and understandable )

at this moment i have following query

var madeReservations = from r in reservationRepo.Query<Reservation>() //standard query
                                   where (r.StartUsage <= _reservation.StartUsage && r.EndUsage >= _reservation.EndUsage)
                                   || (r.StartUsage <= _reservation.EndUsage && r.EndUsage >= _reservation.EndUsage)
                                   || (r.StartUsage >= _reservation.StartUsage && r.EndUsage <= _reservation.EndUsage)
                                   || (r.StartUsage <= _reservation.StartUsage && r.EndUsage >= _reservation.EndUsage)
                                   select r;





_reservation是选定的日期和预订都是预订的...



我的代码有效,但是当我只选择一天(_reservation)时,不会返回任何内容...



有没有人看到这个问题?



提前感谢!!

ps抱歉我的英语不好



the _reservation is the selected date and Reservation is all te made reservations...

My code works but when I only select one day (_reservation) nothing is returned...

Does anyone see the problem??

thanks in advance!!
ps sorry for my bad English

推荐答案

我不确定这会有所帮助,但你应该能够简化为:



r.StartUsage< _reservation.EndUsage&& r.EndUsage> _reservation.StartUsage
I'm not sure this will help, but you should be able to simplify that to:

r.StartUsage < _reservation.EndUsage && r.EndUsage > _reservation.StartUsage


EndUseage设置不正确=>我已将此更改为当天的最后一个可能时间。
The EndUseage was set incorrectly => I have change this to the last possible time of that day.


这篇关于选择两个日期之间的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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