Announcement

Collapse
No announcement yet.

How to use datepicker with custom format

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use datepicker with custom format



    Hello I'm try to get from the user the date and time at the same datepicker so I try to do 21/06/2019 23:38 this format(dd/MM/yyyy hh:mm)

    I use with Microsoft Date and Time Picker control version 6.0


    public Sub bTNOK_Click()
    Cells(1,1).Value = Format(DTPicker1.Value, "dd/MM/yyyy hh:mm")
    End Sub
    public Sub UserForm_Initialize()
    With DTPicker1
    .Format = dtpCustom
    .CustomFormat = "dd/MM/yyyy hh:mm"
    End With
    End Sub

    on the properties of datepicker

    CustomFormat ["dd/MM/yyyy hh:mm"]

    Format [3 - dtpCustom)

    Value [21/06/2019]

    when I run this the Value of cell 1,1 is "30/12/1889 00:00" so how can I fix it?

  • #2


    Refer similar thread https://www.ozgrid.com/forum/forum/h...ritten-to-cell

    Try formatting cell A1 with your custom format and then change the code to:
    Code:
    Public Sub bTNOK_Click()
      Cells(1,1).Value = DateValue(Format(DTPicker1.Value, "dd/MM/yyyy hh:mm"))
    End Sub

    Comment

    Working...
    X