简体   繁体   中英

check the license generated dates belongs to this year

I have got two dates on which legacy license has been generated by a customer

These are the date formats 02-03-2015, 09-08-2015 , so i need to give him a error saying that u have exceeded the license generation count.

because, only two times a customer can generate the license in a year, I am struggling how to compare the two given dates with in the year and whether this belongs to this year (or) not ..

I am using C# for this validation , would any one please suggest nay idea on how to do this ...

Many thanks in advance

I would recommend reading this link: Calculate difference between two dates (number of days)?

(EndDate - StartDate).TotalDays

If you have result > 365 then you can assume that user had exceeded licence generation count

Here's how I'd do it:

    private bool AllowToRenew(List<DateTime> renewalDateList)
    {
        var date = renewalDateList.OrderBy(x => x).First().AddYears(-1);
        return renewalDateList.Count(x => x > date) > 1;

    }

Do a SELECT on your DB table with the licenses where you check for the year of the createdAt Date and the user

SELECT COUNT(*) FROM licTable WHERE year(createdate_column) = 2015 AND user = 123

If the result (count of the returned records) is >= 2 then you throw an error!

您可以为此使用RangeValidator ,将类型设置为Date并从后面的代码中设置Min和Max

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