简体   繁体   中英

Dtpicker in VB6

I am able to format my dtpicker using below code.

Private Sub Form_Load()
 DTPicker1.Format = dtpCustom
 DTPicker1.CustomFormat = "yyyy/MM/dd"
 DTPicker1.Value = Format(Date, "yyyy/MM/dd")
 End Sub

After get dtpicker value using below code

 Private Sub Command1_Click()
    Label34.Caption = DTPicker1.Value
    End Sub

But result is not formatted like as dtpicker displayed value.

Dtpicker value : 2015/05/26

Label34 Value  : 05/26/2015

How to rectify this issue ...?

Use format function (same you did for DatePicker) when assigning value to your label :

Private Sub Command1_Click()
    Label34.Caption = Format(DTPicker1.Value, "yyyy/MM/dd")
End Sub

Or even better, get format from DatePicker:

Private Sub Command1_Click()
    Label34.Caption = Format(DTPicker1.Value, DTPicker1.CustomFormat)
End Sub

I don't remember, but maybe DatePicker has a property giving you its value as text (having the correct format).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM