Reputation: 45
I have datetime (5/24/2013
)
I want to split them into 3 strings like
I need CODES from VB.NET
String 1 = 5
String 2 = 24
String 3 = 2013
Upvotes: 1
Views: 5104
Reputation: 2089
You could try this method
dim dbDate1 as Date
dim string1 as string
dim string2 as string
dim string3 as string
dim number1 as integer
dim number2 as integer
dim number3 as integer
' Strings
string1 = dbDate1.Day().ToString()
string2 = dbDate1.Month().ToString()
string3 = dbDate1.Year().ToString()
and if you wanted a number instead of a string simply remove the ".ToString()" from the end of the line
' Numbers
number1 = dbDate1.Day()
number2 = dbDate1.Month()
number3 = dbDate1.Year()
It should work the same whether your data is DATE or DATETIME object
Upvotes: 0
Reputation: 125630
Use the appropriate DateTime
properties:
Dim value As New DateTime(2013, 5, 24)
Dim dayString As String = value.Day.ToString()
Dim monthString As String = value.Month.ToString()
Dim yearString As String = value.Year.ToString()
Upvotes: 1
Reputation: 13033
If your date is a string, you have to parse it first:
Dim dt As DateTime = DateTime.ParseExact("5/24/2013", "d", Nothing)
Dim day As String = dt.Day.ToString()
Dim month As String = dt.Month.ToString()
Dim year As String = dt.Year.ToString()
Upvotes: 0