TimeValue - VBScript


Overview

The TimeValue function converts a string representing a time value into a Date object. It is useful for parsing time stamps from text or converting text-based time values into a format that can be used in calculations.

Syntax

TimeValue(dateString)

Parameters:

  • dateString: A string representing a time value, in one of the supported formats (see Examples).

Options/Flags

None

Examples

Simple example:

Dim timeValue
timeValue = TimeValue("10:30:15 AM")

Converting a string with a date component:

Dim dateTime
dateTime = TimeValue("2023-03-08 10:30:15")

Supported time formats:

  • hh:mm:ss AM/PM (12-hour format)
  • hh:mm AM/PM
  • hh:mm:ss (24-hour format)
  • hh:mm
  • hh

Common Issues

  • Incorrect formatting of the input string can lead to invalid time values.
  • Leading zeros in time values (e.g. “09:30”) may need to be explicitly included in the input string.

Integration

TimeValue can be combined with other VB Script commands for date and time manipulation, such as DateAdd, DateDiff, and TimeSerial.

  • Date
  • DateSerial
  • DateValue
  • DateTime