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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

royUK

Well-known Member
Joined
Jul 24, 2002
Messages
1,606
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
 

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,329
Office Version
  1. 365
Platform
  1. Windows
Try this.
Code:
ws.Cells(lRow, 13).Value = TimeValue(DTPicker1.Value)
 

royUK

Well-known Member
Joined
Jul 24, 2002
Messages
1,606

ADVERTISEMENT

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
 

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
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 :):):):)
 

royUK

Well-known Member
Joined
Jul 24, 2002
Messages
1,606

ADVERTISEMENT

Great, what are you doing with it?
 

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,329
Office Version
  1. 365
Platform
  1. Windows
What's the problem with including the seconds?

If you don't want to see them then just format appropriately.
 

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,332
Messages
5,769,470
Members
425,552
Latest member
learnerrr

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
Top