0

I have End Date in my DB table. On load I want to store it in an Integer variable. I want to use this month in a loop as an end of the loop.

objAcademicSession.Load()
Dim months as integer
months = objAcademicSession.EndDate

Now I want to end my loop on months.

2
  • 1
    please provide an example of what you have and what you want, otherwise no one will understand what you actually need and what's the problem Commented Jun 12, 2015 at 7:04
  • show how you want to use your month variable in the loop, show example of string in the EndDate property. Please help us to help you, instead of getting answers with If you have... or I assume... Commented Jun 12, 2015 at 14:46

2 Answers 2

1

If your Variable has the Data Type: "Date/DateTime", then you can just use this:

months = objAcademicSession.EndDate.month

If your Variable has the Data Type: "String", then you can use:

months = Convert.toInt32(objAcademicSession.EndDate)

And if you need to "split" the String because it contains the full date and you just need the month, look at this: "VB.NET - Split String"

You can just "cut" the needed part out. But just if you have a date like this: "2014/4/4 16:30:19". Otherwise use the Code above.

Sign up to request clarification or add additional context in comments.

6 Comments

No i want to use this Variable for my FOR LOOP. So i need this to be an integer
.month is a Function that provides you with the month number as an Integer. -- How does your objAcademicSession.EndDate look like? -- What Data Type is it? -- Please provide more Informations! -- And what do you even want to process?
Check my Question Again @sonorpearl
The Problem still remains: What Data Type is your objAcademicSession.EndDate? -- How does your DB Structure look like? -- And @Shafay: .month Should do the job.
objAcademicSession.EndDate is of type String
|
0

objAcademicSession.EndDate is of type String ... I want to use this month in a loop as an end of the loop.

Assuming EndDate is "1" thru "12":

objAcademicSession.Load()
Dim months As Integer
If Integer.TryParse(objAcademicSession.EndDate, months) Then
    For i As Integer = 1 To months
        Debug.Print(i)
    Next
End If

If you have full dates in EndDate, please provide us with examples of what they might look like.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.