Name

TimeSerial Function

Syntax

TimeSerial(hour, minute, second)
hour

Use: Required

Data Type: Integer

A number in the range 0 to 23.

minute

Use: Required

Data Type: Integer

Any valid integer.

second

Use: Required

Data Type: Integer

Any valid integer.

Return Value

A Date.

Description

Constructs a valid time given a number of hours, minutes, and seconds.

Rules at a Glance

  • Any of the arguments can be specified as relative values or expressions.

  • The hour argument requires a 24-hour clock format; however, the return value is always in a 12-hour clock format suffixed with A.M. or P.M.

  • If any of the values are greater than the normal range for the time unit to which it relates, the next higher time unit is increased accordingly. For example, a second argument of 125 is evaluated as 2 minutes 5 seconds.

  • If any of the values are less than zero, the next higher time unit is decreased accordingly. For example, TimeSerial(2,-1,30) returns 01:59:30.

  • If any of the values are outside the range -32,768 to 32,767, an error occurs.

  • If the value of any parameter causes the date returned by the function to fall outside the range of valid dates, an error occurs.

Programming Tips and Gotchas

Because TimeSerial handles time units outside of their normal limits, it can be used for time calculations. However, because the DateAdd function is more flexible and is internationally aware, it should be used instead.

Get VBScript in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.