Substring out of range exception when I'm pretty sure the arguments are in range : I'm getting System.ArgumentOutOfRangeException error message when I'm trying  to substring a year off of a string which is in DateTime format (*"mm/dd/yyyy hh:mm:ss xx"*).

            for(int i = 0; i < elementCounter; i++)
            {
                String stringDate = Convert.ToString(DatumPocetka[i]);
                DPGodina[i] = stringDate.Substring(stringDate.Length - 16, 4);
            }

DatumPocetka is an ArrayList with string type values which are in DateTime format I mentioned earlier.<br><br>I have to calculate the starting character from the back of the string though. I don't know the index where the year starts when I'm calculating it from the beginning because days and months can be single and double digits. It's easier to calculate it from the back because the time part of the string stays static. (*"mm/dd/__yyyy hh:mm:ss xx__"*) this part of the string always has 16 characters, so that's why I'm subtracting the length by 16.<br>Even Visual Studio says that stringDate.Length is equal to 21, but I'm still getting the ArgumentOutOfRangeException. (I tried posting a picture but I can't because I don't have 10 reputation yet)

I have tried doing this with List<*DateTime*> using *name.Year.ToString();* but that did not work either.

I have probably explained things that I didn't need to because they are self explanatory, but this is my first post so I'm sorry. <br><br> Thanks.

