easy one for you guys,
i have a date picker, then i need to split into 3 variables on a button click.
i also need the \ removing.
i presume it will be simple enough :S
thanks in advance
Printable View
easy one for you guys,
i have a date picker, then i need to split into 3 variables on a button click.
i also need the \ removing.
i presume it will be simple enough :S
thanks in advance
Sorry if I've misunderstood.
You can split the date at every" \" and each piece enters the array so you can reference the first piece using array(0) the second using array(1) and the third using array(2)
Dim array() As String = variablename.Split("\")
(You may have to convert the date into a string?)
I think that's worth a try :)
thanks ill give it a go :)
You should not be splitting up the String representation of the date returned by the DateTimePicker's .Text property.
Instead, work with the DateTimePicker's .Value property which returns a Date and manipulate that using the methods and properties of the DateTime Structure.
Use the DateTime's Day, Month and Year properties if you need Integer values.
If you need String values, then use its ToString method, passing the required Format String as an argument.
For example
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dt As DateTime = DateTimePicker1.Value Dim day As Integer = dt.Day Dim month As Integer = dt.Month Dim year As Integer = dt.Year Dim dayString As String = dt.ToString("dd") Dim monthString As String = dt.ToString("MMMM") Dim yearString As String = dt.ToString("yyyy") MessageBox.Show(String.Format("{0}{6}{1}{6}{2}{6}{6}{3}{6}{4}{6}{5}", _ day, month, year, dayString, monthString, yearString, _ Environment.NewLine)) End Sub
which, in English speaking cultures, will give values like:
Integers:
17
2
2013
Strings:
17
February
2013