开发者

time interval in c#

开发者 https://www.devze.com 2022-12-22 22:28 出处:网络
I am having start time and en开发者_JAVA技巧d time as two fields in my database of type Datetime, Now i want thatstart time and end time selected by user should not fall within the interval of start t

I am having start time and en开发者_JAVA技巧d time as two fields in my database of type Datetime, Now i want that start time and end time selected by user should not fall within the interval of start time and end time that are already present in database. How to do this validation.


Firstly, ensure that yourStartTime < yourEndTime, if you haven't already.

Then you can run this query on your database:

SELECT COUNT (*) FROM [table]
WHERE [table].EndTime > yourStartTime
      AND [table].StartTime < yourEndTime

If the count is non-zero, you've failed validation.


You could use TimeSpan ts = endTime.Subtract(startTime); which will give you the difference between the 2 dates. Then, selecting the results from the database you can use the DATEDIFF method in order to compare these values.

If I have understood the question correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号