Solved

IncrementDate Function

Posted on 2007-04-02
3
185 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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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