Results 1 to 2 of 2

Thread: datetime picker info

  1. #1
    hendrikbez is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2005
    Location
    South Afica
    Posts
    35
    Reputation
    142

    datetime picker info

    I have a form with a button, textbox and a datetimepicker.

    I want to click on datetimepicker and choose a date, then click on button, then the date should show in the textbox.
    After I have click on datetimepicker and then the button ,it shows the date, but in the wrong format.

    Here is my code, I am using it in my button code

    Code:
    DateTimePickerOutDate.Format = DateTimePickerFormat.Custom
    DateTimePickerOutDate.CustomFormat = "dd MMMM yyyy"
    txtSearchDateOut.Text = DateTimePickerOutDate.Value
    The date that I want it to display must be dd mmmm yyyy (09 October 2012), but is shows in the textbox as 10/09/2012 2:43:22 PM

    What am I doing wrong, is there someplace that I must change the datetimepicker values as well.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,813
    Reputation
    1707
    The Value property of the DateTimePicker returns a DateTime. It's just a DateTime like any other, which no specific knowledge of the DateTimePicker or the format it displays its contents in. If you want the data displayed in the TextBox using the same format as the DateTimePicker then use the Text property of the DateTimePicker, which is already a formatted String, rather than the Value.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •