Time, Time$ Statements
See Also Example
Sets the system time.
Time[$] = expression
For the Time statement, expression must be a String formatted as a time or a Variant If expression is a String (or a Variant of VarType 8), times can be entered using a 12- or 24-hour clock. For example, of VarType 7 (Date) or of VarType 8 (String)."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):
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.
Date, Date$ Functions
Date, Date$ Statements
Time, Time$ Functions
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.
Msg = "You did not enter a valid time."
MsgBox Msg ' Display message.