|
-
Feb 17th, 2013, 07:18 AM
#1
Thread Starter
Junior Member
date picker
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
-
Feb 17th, 2013, 07:30 AM
#2
New Member
Re: date picker
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
-
Feb 17th, 2013, 07:32 AM
#3
Thread Starter
Junior Member
Re: date picker
thanks ill give it a go
-
Feb 17th, 2013, 09:42 AM
#4
Re: date picker
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|