Solved

IncrementDate Function

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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