Today one of friend asked me, how to find century from the year thru C# code. The following code snippet helps:
int year = 2010;
int cent = year / 100;
year %= 100;
if (year > 0)
cent = cent + 1;
Console.WriteLine("{0}C",cent);
Output:
21C
result = year.ToString().Length == 1 || year.ToString().Length == 2 ? "1" : (Convert.ToInt32(year.ToString().Substring(0, (year.ToString().Length - 2))) + 1).ToString();
ReplyDelete