Results 1 to 4 of 4

Thread: date picker

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2013
    Posts
    18

    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

  2. #2
    New Member
    Join Date
    Feb 2013
    Posts
    2

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2013
    Posts
    18

    Re: date picker

    thanks ill give it a go

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.     Dim dt As DateTime = DateTimePicker1.Value
    4.  
    5.     Dim day As Integer = dt.Day
    6.     Dim month As Integer = dt.Month
    7.     Dim year As Integer = dt.Year
    8.  
    9.     Dim dayString As String = dt.ToString("dd")
    10.     Dim monthString As String = dt.ToString("MMMM")
    11.     Dim yearString As String = dt.ToString("yyyy")
    12.  
    13.     MessageBox.Show(String.Format("{0}{6}{1}{6}{2}{6}{6}{3}{6}{4}{6}{5}", _
    14.                                   day, month, year, dayString, monthString, yearString, _
    15.                                   Environment.NewLine))
    16. 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
  •  



Click Here to Expand Forum to Full Width