0

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

leppie
  • 115,091
  • 17
  • 196
  • 297
Glory Raj
  • 17,397
  • 27
  • 100
  • 203
  • You means that user will input 2 datetimes (date1 and date2), and you need to check if the period between those datetimes is in current year or not? – tdat00 Jan 12 '16 at 07:37
  • I do not understand. Do you mean the time windows between the two given dates needs to be < 365 days or do you need to check if both dates are in the year same year for example 2015? – STORM Jan 12 '16 at 07:56
  • @tdat00 sorry for late reply .. I mean any customer cannot generate more than two licenses per year this is restriction that i need to put .... would you please help.. – Glory Raj Jan 12 '16 at 12:57
  • @STORM sorry for late reply .. I mean any customer cannot generate more than two licenses per year this is restriction that i need to put .... would you please help. – Glory Raj Jan 12 '16 at 12:58
  • Do you mean within the year 2015 for example only two times? Or between the two dates or we need a clearer description of what you want to do. – STORM Jan 12 '16 at 13:01
  • When i correctly understand your requirement that you only have to check if these two years belong to the same year, than please take the second part of my answer! – STORM Jan 12 '16 at 13:03
  • with in the year a customer can able to generate only two license and if he try to generate one more i need to warn saying that u have exceeded the limit for current year .. would you please help on this ... – Glory Raj Jan 12 '16 at 13:03
  • i have got db structure like this createdDate, licKey , userName... so i need check that createdDate with the user .. – Glory Raj Jan 12 '16 at 13:05
  • I have edited my answer completely! Please have a look at it. I think it will solve your problem. – STORM Jan 12 '16 at 14:16

3 Answers3

2

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;

    }
Community
  • 1
  • 1
Edgaras
  • 154
  • 9
  • @Edgaras sorry for late reply .. I mean any customer cannot generate more than two licenses per year this is restriction that i need to put .... would you please help. – Glory Raj Jan 12 '16 at 12:58
  • Does that makes any sense to you? renewalDateList is your list of dates "02-03-2015, 09-08-2015" – Edgaras Jan 12 '16 at 14:01
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!

STORM
  • 4,005
  • 11
  • 49
  • 98
0

You can use RangeValidator for this, set the type as Date and set the Min and Max from code behind

Anup Sharma
  • 2,053
  • 20
  • 30