"Doug" <dn******@dtgnet.com> wrote:
Is there a format that can be used in DateTime.ToString()
that will allow you to get only the century of a given year.
"yy" of course doesn't work, that returns the year itself,
not the century.
Well, get the full year that way, extract the first two digits of the
year (e.g. "19" from "1984"), and add one (since 19xx is in the 20th
century, for example).
string firstTwoDigits = yearString.Substring(0, 2);
int century = Convert.ToInt32(firstTwoDigits) + 1;
You don't have to worry about years with fewer than two digits,
because years before about 1750 aren't supported. (That's when the
modern Gregorian calendar came into force.)
Eq.