Format time to hh:mm? and 24h?

R

Rolf Edberg

Hi
I am trying to get time to format to only show hour and minutes (no
seconds). But this code does not work. How shall I do?
And how can I make it to show 24h in stead of AM/PM?
The Region Date and Time on my pc is changed to English(USA) to simplify it.

Thanks
Rolf

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As Date

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox (cTime)

End Sub
 
B

Bob Phillips

Try

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As String

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox cTime

End Sub

HTH

Bob
 
F

fisch4bill

How about this:

Sub HoursAndMinutes()
Dim aTime As String

aTime = "10:31:42"
MsgBox Left(aTime, Len(aTime) - 3)

End Sub

All this does is chop the seconds and colon off the end of the initial
string, and doesn't require the additional variables or code steps.

HTH
Bill
 
R

Rolf

Thank you for your suggestion! I will show my bigger problem then it easier
to find the right solution( in the general list). Rolf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top