Time, Time$ Statements

See Also2EPFTY              Example2ET90O8>Low

Sets the system time.

Syntax

Time[$] = expression

Remarks

For the Time statement, expression must be a String formatted as a time or a Variant8PHEAW3 of VarType7A68ZTZ 7 (Date) or of VarType 8 (String).  If expression is a String (or a Variant of VarType 8), times can be entered using a 12- or 24-hour clock.  For example, "2:24PM" and "14:24" are both valid time arguments.  If expression is not already a Variant containing a valid time, Time attempts to convert it using the time separators specified in the International section of the Windows Control Panel.  If it can't be converted to a valid time, an error occurs.

For Time$, expression must have one of the following forms, where hh is the hour (00-23), mm is the minute (00-59), and ss is the second (00-59):

Form             Description

 

hh                  Sets the hour; the minute and the second default to 00.

hh:mm           Sets the hour and the minute; the second defaults to 00.

hh:mm:ss      Sets the hour, the minute, and the second.

 

A 24-hour clock is used, so 8:00 P.M. is entered as 20:00:00.

 

Note   If you use the Time[$] statement to set the time with versions of MS-DOS earlier than 3.3, the change remains in effect only until you change it again or turn off your computer.  Many computers have a battery-powered CMOS RAM that retains date and time information when the computer is turned off.  However, to permanently change the time in the CMOS RAM on computers running earlier versions of MS-DOS, you may have to use your Setup disk or perform some equivalent action.  Refer to the documentation for your particular system.

 


See Also

Date, Date$ Functions3E3X9E

Date, Date$ Statements3E3X9R

Time, Time$ FunctionsQ3GPPU


Time, Time$ Statements Example

The example uses the Time statement to set the computer system time to a new time entered by the user.  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.

   Else

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

   End If

   MsgBox Msg                            ' Display message.

End Sub