Search code examples
vb.netwinformsdatetimepicker

DateTimePicker displays date in wrong format


I have a ListView where ID and date is entered. The date is in the format dd/MM/yyyy.

enter image description here

In the SelectedIndexChanged Property I have written this

If lvRecruitmentList.SelectedItems.Count > 0 Then
   txtID.Text = lvRecruitmentList.SelectedItems(0).Text
   dtpRecievedOn.Text = lvRecruitmentList.SelectedItems(0).SubItems(1).Text
End If

In the dtpRecievedOn DateTimePicker, the Date is displayed like this

enter image description here

I have set the following properties via designer

dtpRecievedOn.Format = Custom
dtpRecievedOn.CustomFormat = "dd/MM/yyyy"

Edit 1 :

Notice that in the ListView the Date is in the format dd/MM/yyyy and in the dtpRecievedOn the Date is in the format MM/dd/yyyy.

How can I make dtpRecievedOn display date in the format dd/MM/yyyy


Solution

  • Dim str As String() = "2/1/2000".Split("/"C)
    Dim dt As New DateTime(Convert.ToInt16(str(2)), Convert.ToInt16(str(1)), Convert.ToInt16(str(0)))
    dateTimePicker1.Value = dt.Date