method to calculate expiry date in c# code example
Example: how to calculate expiry date in c#
string[] expiryDateDbSplit = expiryDate.Split('-');
int expYrs = Convert.ToInt32(expiryDateDbSplit[0]);
int expMth = Convert.ToInt32(expiryDateDbSplit[1]);
int expDays = Convert.ToInt32(expiryDateDbSplit[2]);
DateTime start = new DateTime(expYrs, expMth, expDays);
int yrs = System.DateTime.Now.Year;
int month = System.DateTime.Now.Month;
int days = System.DateTime.Now.Day;
DateTime end = new DateTime(yrs, month, days);
TimeSpan difference = end - start; //create TimeSpan object
int totalDays = difference.Days;
int totalYears = (end.Year - start.Year);
if (totalDays <= 30)
{
penaltyAmt = 0;
}
else if (totalDays > 30 && totalDays <= 180)
{
penaltyAmt = 500;
}
else if (totalDays > 180)
{
if (totalYears > 0)
{
penaltyAmt = 500 * totalYears;
}
else
{
penaltyAmt = 500;
}
}