DTPicker1 Format

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
Hello,

How can I retrieve from UserForm DTPicker1 to a Cell only the time value?

I tried:
Code:
Private Sub CommandButton5P1_Click()
Dim MyDate1 As Date
MyDate1 = DTPicker1.Value

DTPicker1.Format = dtpTime

DTPicker1.Value = Format(Time, "Short Time")
'or
DTPicker1.Value = Format(MyDate1, "h:mm")

ws.Cells(lRow, 13).Value = MyDate1
'or
ws.Cells(lRow, 13).Value = DTPicker1.Value
End Sub
I really couldn't make it by myself, trying to read all kind of topics about DTPicker1 Format :(

The result is or:
12:00:00 AM - returns the defaul value in the cell

7/20/2007 11:44 - returns the date + the correct time filled in the UserForm

I'd like to return in the cell only the "h:mm".
Thanks in advance :rolleyes:
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Select the date picker in design View & in the properties Window you will see Format. This is a dropdown, try changing it to 2 dtpTime
 
Upvote 0
Yes, it's was the first thing I did. On the UserForm the control is giving the time only, but when I try to ws.Cells(lRow, 13).Value = DTPicker1.Value then I have the Date + Time or only 12:00:00 AM
 
Upvote 0
Try this.
Code:
ws.Cells(lRow, 13).Value = TimeValue(DTPicker1.Value)
 
Upvote 0
the datepicker is not a clock so you have to give it a time or it will default to 12 (00;00:00)
Code:
Private Sub UserForm_Activate()
    With Me
        .DTPicker1.Format = dtpTime
        .DTPicker1.Value = Now
    End With

End Sub

Test

Code:
Private Sub CommandButton1_Click()
    MsgBox Format(Me.DTPicker1.Value, "hh:mm:ss")
End Sub
 
Upvote 0
Thanks, i didn't get the whole picture before and I missed that row: DTPicker1.Value = Now

Now I can make it work the way I like :):):):)
 
Upvote 0
Very very strange...from all of a sudden it works now only with this single row:

ws.Cells(lRow, 12).Value = Format(DTPicker1.Value, "h:mm")

without:
With Me
.DTPicker1.Format = dtpTime
.DTPicker1.Value = Now
End With

I tested it 100 times before with all kind of different combinations but i couldn't reach this easy one.

Norie - this one also works but it adds the seconds which I don't need.
ws.Cells(lRow, 13).Value = TimeValue(DTPicker1.Value)

Roy - I need 2 DTPickers on a UserForm in order to choose a starting - ending time for a task. I calculate a total working time for each task of course.

Do think there's some other better method than two DTPickers?
 
Upvote 0
What's the problem with including the seconds?

If you don't want to see them then just format appropriately.
 
Upvote 0
Norie, I formated like this ws.Cells(lRow, 12).Value = Format(DTPicker1.Value, "h:mm") and it's appropriately for me..when I don't need seconds I awlays try to put things as simple as possible..

I also wonder about if 2 things are possible:

1) on the UserForm DTPicker not to see seconds too. When I choose Format Property 2 - dtpTime, it shows the seconds.

2) on the UserForm DTPicker the time format - 23:00 not 11:00:00 PM.
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top