An exception error occurs in this piece of code:
System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
What caused:
[__DynamicallyInvokable] public DateTime(int year, int month, int day) { this.dateData = (ulong) DateTime.DateToTicks(year, month, day); }
When executing this code, it looks like this:
private static long DateToTicks(int year, int month, int day) { if (year >= 1 && year <= 9999 && (month >= 1 && month <= 12)) { int[] numArray = DateTime.IsLeapYear(year) ? DateTime.DaysToMonth366 : DateTime.DaysToMonth365; if (day >= 1 && day <= numArray[month] - numArray[month - 1]) { int num = year - 1; return (long) (num * 365 + num / 4 - num / 100 + num / 400 + numArray[month - 1] + day - 1) * 864000000000L; } } throw new ArgumentOutOfRangeException((string) null, Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay")); }
The only way the method throws an exception is when the year is less than 1 or more than 9999, and the month is not between 1 and 12. Therefore, I suggest that you make sure that you pass valid dates.
source share