.NET和Sql:在两个日期之间选择(开始和结束时间) [英] .NET and Sql: Select between two dates ( start and end time)

查看:144
本文介绍了.NET和Sql:在两个日期之间选择(开始和结束时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!你可以帮我这个吗/



我试图避免冲突,例如我输入:



房间|一天| timeFROM | timeTO

ab222 | MON |上午7:00 | 10:00 AM



然后如果我打算输入这样的另一个条目

ab222 | MON |上午8:00 |上午11:00



时间冲突因为已经有7-10而且它不应该接受8-11。



我怎么能在.net中这样做?



请帮助!谢谢! :D

hello! can you help me with this one/

im trying to avoid conflicts here for example i typed in:

ROOM | DAY | timeFROM | timeTO
ab222 | MON | 7:00 AM | 10:00 AM

then if im going to typed in another entry like this
ab222 | MON | 8:00 AM | 11:00 AM

the time is conflict because there is already 7-10 and it should not accept the 8-11.

how can i do this in .net?

please help! thanks! :D

推荐答案

在数据库中执行。检查简单明了。您需要检查您的开始日期或结束日期是否都是> timeFrom和< time to ............................................................................................. b $ b(timeFrom> @endTime和timeTo< @endTime)



将选择所有冲突的时间表。这样的事情。如果没有,那就没有冲突。



如果可以让数据库执行,不要从数据库中提取数据来处理代码。
Do it in the DB. The check is simple and obvious. You need to check if your start date or your end date is both > timeFrom and < timeTo.

select * from tblRooms where
(timeFrom > @startTime and timeTo < @startTime) or
(timeFrom > @endTime and timeTo < @endTime)

will select all the schedules that conflict. Something like that. If there's none, there's no conflict.

Never pull data from the DB to process in code if you can get the DB to do it.


或者你可以在代码隐藏(C#)中执行此操作,请查看对这些内容有用的文章。

.NET时间段库 [ ^ ]
Alternatively you could do this in code-behind(C#), check this article which is useful for these things.
Time Period Library for .NET[^]


这篇关于.NET和Sql:在两个日期之间选择(开始和结束时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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