简体   繁体   中英

How can i check conflict in date time

How could i know if there's a conflict , example i have here User Start time 7:00 AM End time 12:00 PM. Now if i add new Entry it should always CHECK the time. It shouldn't be the same with the first one. Meaning to say his time should be 12:00 PM Onwards. If his time is between 7-12. Example 11:00 AM this is CONFLICT since the first one has already workd in that time.

To be more clear First entry .7:00 Am-12:00pm Second entry 12:00pm-3pm Third entry 3:00pm-7:00pm And so on. Thank you to those who will help.

Just do some checks on the three dates you are using. You should make an object for this but here is a simple code section of what it should look like.

        var start = DateTime.Now;
        var end = start.AddHours(3);
        var newStart1 = start.AddHours(2);
        if(newStart1> start && end<= newStart1)
        {
            //valid time
        }
        else
        {
            throw new Exception("Invalid start time.");
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM