简体   繁体   English

多个日期范围,并检查它是否是连续的。 C#MVC

[英]multiple date range and check if it is sequential. c# MVC

We have this project and one of the business requirement is it allows the client to input a multiple date range and check the individual dates if it is sequential/continuous or not to the others. 我们有这个项目,业务需求之一就是允许客户输入多个日期范围,并检查单个日期是否连续/连续。

eq. eq。

INPUT 输入

startdate - enddate 开始日期-结束日期

10/24/2016 - 10/24/2016 2016年10月24日-2016年10月24日

10/26/2016 - 10/28/2016 2016年10月26日-2016年10月28日

OUTPUT 输出值

10/24/2016 - 10/24/2016 - NOT SEQUENTIAL 10/24/2016-10/24/2016-非连续

10/26/2016 - 10/26/2016 - SEQUENTIAL 2016/10/26-2016/10/26-连续

10/27/2016 - 10/27/2016 - SEQUENTIAL 2016/10/27-2016/10/27-连续

10/28/2016 - 10/28/2016 - SEQUENTIAL 2016/10/28-2016/10/28-连续

For now I am playing around this solution Check if date range is sequential in c#? 现在,我正在解决这个问题。 检查日期范围在c#中是否是连续的? but i hope we i can find a better solution on how to properly do it. 但我希望我们能找到有关如何正确执行的更好的解决方案。

Thank you and have a good day! 谢谢你,有一个美好的一天!

If by "sequential" we mean that the second date is the day after the first date then we can do the following: 如果用“顺序”表示第二个日期是第一个日期之后的那一天,那么我们可以执行以下操作:

private bool CheckSequential(DateTime date1, DateTime date2)
{
    // strips off time portion
    var d1 = date1.Date;
    var d2 = date2.Date;

    // add 1 to first date
    d1 = d1.AddDays(1);

    // compare them
    if(DateTime.Compare(d1, d2) == 0)
       return true;
    else
       return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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