TimeSerial - VBScript


The TimeSerial command in VB Script constructs a time value from specified hour, minute, and second values. It is primarily used to create custom time values for various scenarios, such as setting alarm times or comparing time intervals.


TimeSerial(Hours, Minutes, Seconds)


  • Hours: Required. Integer value representing the hour (0-23).
  • Minutes: Required. Integer value representing the minutes (0-59).
  • Seconds: Required. Integer value representing the seconds (0-59).


  • Simple Example: Create a time value for 10:30 AM.
Dim timeValue
timeValue = TimeSerial(10, 30, 0)
  • Complex Example: Compare a time value with the current system time.
Dim nowTime
nowTime = Time
Dim targetTime
targetTime = TimeSerial(15, 0, 0)

If nowTime >= targetTime Then
    'Do something
End If

Common Issues

  • Invalid Input Values: Ensure that the input values are valid (within their respective ranges). Invalid values will result in an error.
  • Time Value Overflow: If the result of the time calculation exceeds the maximum time value (23:59:59), the time will wrap around to the beginning of the day.


TimeSerial can be combined with other VB Script commands for advanced tasks:

  • DateSerial: Create a combined date and time value by combining the output of TimeSerial with DateSerial.
  • FormatDateTime: Convert the time value into a formatted string representation using the FormatDateTime function.
  • Date: Returns the current system date.
  • Time: Returns the current system time.
  • Now: Returns the current system date and time in a combined format.