• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

IncrementDate Function

Increment month or year depending on if it is a new year or what have you.

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

        End Function

        Public Function GetBusinessCalendarPeriod(ByVal dbName As String, ByVal DatePeriod As String, ByVal txtMaxPeriod As String) As DataTable

            Dim retVal As New DataTable("BusinessCalendars")
            Dim DtPeriod As String = DatePeriod
            Dim MaxPeriod As Integer = Int32.Parse(txtMaxPeriod)
            Dim cmd As DbCommand
            Dim tmpds As DataSet
            Dim StoredProcName As String = String.Empty

            'We get the divisions
            For Index As Integer = 0 To MaxPeriod - 1
                StoredProcName = dbName & ".dbo.usp_GetDatePeriodFromTo"
                cmd = dbManager.GetStoredProcCommand(StoredProcName)

                dbManager.AddInParameter(cmd, "@YEARMONTH", DbType.String, DtPeriod)
                IncrementDate(DtPeriod, Index + 1) ' Increment by one month.

                'Temporarilly put the results in a dataset so we can check for valid data
                tmpds = dbManager.ExecuteDataSet(cmd)

        End Function
  • 2
1 Solution
Why not use the built in functionality?

Date objects have AddMonths and AddYears built onto them.
mathieu_cuprykAuthor Commented:
Ok this is a string?
Is what a string?

The functions work on datetime objects... if your date is in a string, then you convert to a datetime, apply the function, and can even .ToString() back if needed


Dim dateString As String = "3/3/2007"
Dim myDate As DateTime = Convert.ToDateTime(dateString)
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.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now