Time

Note

In twinBASIC, Time and Time$ are implemented as module-level properties, not as functions/statements like they were in VBx. This has no impact on their behavior. These properties still have the syntax and semantics of the Time and Time$ functions and statements in VBx.

Time Property

Get

Returns a Variant (Date) indicating the current system time.

Syntax: Time [ () ]

Example

This example uses the Time property to return the current system time.

Dim MyTime As Variant
MyTime = Time   ' MyTime contains the current system time.

Let

Sets the current system time.

Syntax: Time = time

time

required Any numeric expression, string expression, or any combination that can represent a time.

If time is a string, Time attempts to convert it to a time by using the time separators specified by the system.

Note

In some versions of Microsoft Windows, including Windows 10 and 11, setting the system time is a privileged operation that requires the process to have relevant permissions.

Note

twinBASIC takes a number as CDate converts it, and sets the time part of the result: Time = 0.25 sets 6:00:00 AM, and so does Time = 1.25. VB6 and 64-bit VBA raise error 13, Type mismatch, for a number, though they take the same value as a Date, such as CDate(0.25).

Example

This example uses the Time property to set the computer system time.

Dim MyTime
MyTime = #4:35:17 PM#    ' Assign a time.
Time = MyTime             ' Set system time to MyTime.

Time$ Property

Get

Returns a String containing the current system time.

Syntax: Time$ [ () ]

Example

This example uses the Time$ property to return the current system time as a string.

Dim MyTime$
MyTime = Time$  ' MyTime contains the current system time as a string.

Let

Sets the current system time from a string.

Syntax: Time$ = time

time

required A string expression representing a time from 0:00:00 (12:00:00 A.M.) to 23:59:59 (11:59:59 P.M.), inclusive.

Note

In some versions of Microsoft Windows, including Windows 10 and 11, setting the system time is a privileged operation that requires the process to have relevant permissions.

Example

This example uses the Time$ property to set the computer system time.

Dim MyTime$
MyTime = "4:35:17 PM"    ' Assign a time.
Time$ = MyTime           ' Set system time.

Common Errors

Error When
13 (&HD), Type mismatch Time is given a string that is not a time, or a number outside the range of dates
-2147467259 (&H80004005), Unspecified error Time$ is given a value that is not a string of the form hh:mm:ss, or one outside 00:00:00 to 23:59:59
Time$ is given a time in another form VB6 reads, such as hh:mm or hh
94 (&H5E), Invalid use of Null Time$ is given Null
Time is given Null

Note BETA 1034

When Time$ is given a value that is not a string of the form hh:mm:ss, or one outside 00:00:00 to 23:59:59, VB6 and 64-bit VBA raise error 5 (&H5), Invalid procedure call or argument, instead.

Note BETA 1034

When Time$ is given a time in another form VB6 reads, such as hh:mm or hh, VB6 and 64-bit VBA raise no error.

Note BETA 1034

When Time is given Null, VB6 and 64-bit VBA raise error 13 (&HD), Type mismatch, instead.

See Also