Software Development Network>> Visual C#>> How do you do to get only 6 from 2006
Whats wrong with:
int lastDigit = 2006 % 100;
ThE_lOtUs wrote: For all millenium (if it's a number) int subYear = year - ((int)(year/10)*10)
For all millenium (if it's a number)
int subYear = year - ((int)(year/10)*10)
I'm not a mind reader, but I think YoK was essentially just trying to get the sub year of the current millenium.
Your code only works for years 1-9 in any given millnenium.
There probably is a way to do this for any millenium, but I'm too frazzled to think about it .
you can try something like this
string sNumber = "";
int iNumber = 0;
DateTime dt = DateTime.Now;
sNumber = Convert.ToString(dt.year);
iNumber = Convert.ToInt32(sNumber.Substring(3,1));
Hope this helps.
If the year is a number, you can achieve this by just subtracting 2000. This approach will work for all years in this millenium at least .
If it's a string, you could do the following:
int subYear = int.Parse(year) - 2000;
How do you do to get only 6 from 2006
mgalliers
Whats wrong with:
int lastDigit = 2006 % 100;
chandra shekhar
levogiro
I'm not a mind reader, but I think YoK was essentially just trying to get the sub year of the current millenium.
Your code only works for years 1-9 in any given millnenium.
There probably is a way to do this for any millenium, but I'm too frazzled to think about it
.
Michael Koster
For all millenium (if it's a number)
int subYear = year - ((int)(year/10)*10)
codelinezero
you can try something like this
string sNumber = "";
int iNumber = 0;
DateTime dt = DateTime.Now;
sNumber = Convert.ToString(dt.year);
iNumber = Convert.ToInt32(sNumber.Substring(3,1));
Hope this helps.
above8848
int lastDigit = year % 10;
But if the year is in string form, it would have to be:
string lastDigit = year.Substring(year.Length-1, 1);
Or if you KNOW it's a 4-character year:
string lastDigit = year.Substring(3, 1);
GaryKnowles
If the year is a number, you can achieve this by just subtracting 2000. This approach will work for all years in this millenium at least
.
If it's a string, you could do the following: