Solved

IncrementDate Function

Posted on 2007-04-02
3
188 Views
Last Modified: 2012-06-27
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)
            Next

        End Function
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 18838176
Why not use the built in functionality?

Date objects have AddMonths and AddYears built onto them.
0
 

Author Comment

by:mathieu_cupryk
ID: 18838485
Ok this is a string?
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 500 total points
ID: 18838541
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

Example:

Dim dateString As String = "3/3/2007"
Dim myDate As DateTime = Convert.ToDateTime(dateString)
myDate.AddMonths(3)
myDate.ToString
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question