开发者

time interval in c#

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜