Solved

IncrementDate Function

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

765 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