Adding months to a date in VB2005.net

Hello All
I have a datetimepicker giving me a date, and i have  a numericupdowm giving me a number, can anyone tell me how to use the addmonth function to add the 2 together to move along the month of the datetimepicker text output

many thanks
bostonsteAsked:
Who is Participating?
 
abelCommented:
What about something like:

// adding the months to the selected date:
 
DateTime myDate = dateTimePicker1.Value;
myDate = myDate.AddMonths((int)numericUpDown1.Value);
//

Open in new window

0
 
bostonsteAuthor Commented:
have tried somthing similar
            Dim daterange1 As DateTime
            Dim daterange2 As DateTime
               daterange1 = DateTimePicker1.Text
                daterange2 = daterange1.monthadd(CInt(NumericUpDown.Value))

I get the feeling that the monthadd function doesnt exist in vb2005.net or im just using it in the wrong place/context
0
 
UnifiedISCommented:
VB:

Dim myDate As DateTime
myDate = datetimepicker1.Value.AddMonths(numericUpDown1.Value)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
UnifiedISCommented:
datetimepicker1.text is not right, you need to use datetimepicker1.value and it's AddMonths not Monthadd
0
 
abelCommented:
@bostonste: the monthadd method does not exist. You should use the AddMonths method. The code that I showed you was tested and worked. Also note that I used DateTimePicker1.Value and not DateTimePicker1.Text. Using .Value is easier because it is already a date.

If you use IntelliSense you should be able to see immediately that your code does not work, because it gets marked by the IDE for being wrong. Typing the dot at the end of daterange1 should show you that monthadd does not exist...

-- Abel --
0
 
abelCommented:
Apologies, I somehow thought you were doing C#. Here's the exact same code in VB for you to use:

' adding the months to the selected date '
 
Dim myDate As DateTime = dateTimePicker1.Value
myDate = myDate.AddMonths(CInt(numericUpDown1.Value))
 
' end '

Open in new window

0
 
bostonsteAuthor Commented:
thanks chaps, both answers were great
0
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.

All Courses

From novice to tech pro — start learning today.