Time, Time$ Functions

See Also2ECFTY              Example1SJX0US>Low

Returns the current system time.


Time[$][( )]


Time returns a Variant8PHEAW3 of VarType7A68ZTZ 7 (Date) containing a time stored internally as the fractional part of a double-precision number.

The Time$ function returns an eight-character string of the form hh:mm:ss, where hh is the hour (00-23), mm is the minute (00-59), and ss is the second (00-59).  A 24-hour clock is used; therefore, 8:00 P.M. appears as 20:00:00.

The output of the Time$ function is equivalent to:


To set the system time, use the Time$ statement.

See Also

Date, Date$ Functions3E3X9E

Date, Date$ Statements3E3X9R

Time, Time$ StatementsQ3GPQ7

Timer FunctionQ3GPQ6

Time, Time$ Function Example

The example uses the Time function to provide the default time for the input box when prompting the user for a new time.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim Msg, NewTime                      ' Declare variables.

   Msg = "Enter a new time in the form hh:mm:ss"

   NewTime = InputBox(Msg, "", Time)     ' Get user input.

   If Len(NewTime) > 0 Then              ' Check if valid.

      Time = NewTime                     ' Set time.

      Msg = "System time now set to "

      Msg = Msg & Time & "."             ' Put time in message.


      Msg = "You did not enter a valid time."

   End If

   MsgBox Msg                            ' Display message.

End Sub