SoFunction
Updated on 2025-03-10

VBS Tutorial: Functions - TimeSerial Functions

TimeSerial function

Return oneDateSubtypeVariant, contains the specified time, minutes and seconds.

TimeSerial(hour,minute, second)

parameter

hour

Its values ​​are numerical or numeric expressions from 0 (12:00 .) to 23 (11:00 .).

minute

Any numeric expression.

second

Any numeric expression.

illustrate

To specify a moment, such as 11:59:59,TimeSerialThe parameter value of the parameter should be within an acceptable range; that is, the hours should be between 0-23, and the minutes and seconds should be between 0-59. However, a numeric expression can be used to specify a relative time for each parameter, which represents the number of hours, minutes, or seconds before or after a certain moment.

The following example uses an expression of absolute time.TimeSerialThe function returns 15 minutes (-15) before 6 (12-6) hours before noon, or 5:45:00.

Dim MyTime1MyTime1 = TimeSerial(12 - 6, -15, 0) ' return 5:45:00 AM.

When the value of any parameter exceeds an acceptable range, it will correctly carry to the next larger unit of time. For example, if 75 minutes are specified, this time is interpreted as one hour and fifteen minutes. However, if any parameter value exceeds the range of -32768 to 32767, an error will be caused. An error can also result if the time specified directly with three parameters or the time calculated by the expression exceeds an acceptable date range.