Extracting first two digits of a time entry!!

R

roshinpp_77

HI friends,
Could anyone tell me how to extract first two digits of a "Time
value"

For example in cell B10 the content is 12:00 ie..(Time)
I am not able to extract "12" ie the first two digits of that time.

I am getting 0.5013 when taken as text.


Regards,
TIA


Roshin
 
M

Mike

roshinpp_77 said:
HI friends,
Could anyone tell me how to extract first two digits of a "Time
value"

For example in cell B10 the content is 12:00 ie..(Time)
I am not able to extract "12" ie the first two digits of that time.

I am getting 0.5013 when taken as text.


Regards,
TIA


Roshin
Hello,
use this left(range("B10").text,2)

Mike,Luxembourg
 
N

NickHK

Depending what you actually want returned, a string or a number.
Assuming the value is a double formatted as a time:
Public Function GetHourOnly(argRange As Range) As Integer
GetHourOnly = Int(argRange.Value * 24)
End Function
Or
Public Function GetHourOnly(argRange As Range) As String
GetHourOnly = Left(argRange.Text, 2)
End Function

NickHK

"roshinpp_77" <[email protected]>
wrote in message
news:[email protected]...
 
D

Dave Peterson

You can extract the hour, minute or second:

With ActiveSheet.range("B10")
MsgBox Hour(.Value) & vbLf & _
Minute(.Value) & vbLf & _
Second(.Value)
End With
 

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