error in string.

If I put 200401

it gives me 20042

Public Function IncrementDate(ByVal DtPeriod As String, ByVal IncrementAmount As Integer) As String

Dim strResults As String

Dim intYear As Integer

Dim intMonth As Integer

intYear = Int32.Parse(DtPeriod.Substring(0, 4))

intMonth = Int32.Parse(DtPeriod.Substring(4, 2))

intMonth += IncrementAmount

If intMonth > 12 Then

intYear += 1

intMonth -= 12

End If

strResults = intYear.ToString & intMonth.ToString

Return strResults

End Function
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
that is because int.Tostring does not keep leading 0

strResults = intYear.ToString & intMonth.ToString().PadLeft(2, "0")
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.