VBA - Time Value Function



The TimeValue Function converts the given input string to a valid time.

Syntax

TimeValue(StringTime) 

Example

Add a button and add the following function.

Private Sub Constant_demo_Click() 
   msgbox(TimeValue("20:30"))
   msgbox(TimeValue("5:15"))
   msgbox(TimeValue("2:30:58"))
End Sub

When you execute the above function, it produces the following output.

8:30:00 PM
5:15:00 AM
2:30:58 AM
vba_date_time.htm
Advertisements