Hour - VBScript

VB Script Hour


The Hour command in VB Script retrieves the hour (0 – 23) component of the current time. It finds multiple applications in time-related operations, such as calculating time differences, scheduling, and displaying clocks.


  • Date: (Optional) A Date object representing the time to extract the hour from. If omitted, the current time is used.




Example 1: Getting the current hour

Dim currentHour
currentHour = Hour()

Example 2: Calculating the hour difference between two dates

Dim startTime, endTime, timeDiff
startTime = CDate("2023-03-08 14:30")
endTime = CDate("2023-03-08 17:15")
timeDiff = Hour(endTime) - Hour(startTime)

Common Issues

  • Date Argument: Ensure the provided Date object is valid. Invalid dates may result in incorrect or unexpected results.


  • DateDiff: Combine with DateDiff to compute the hour difference between two dates.
  • TimeSerial: Use with TimeSerial to create a new Date object with a specific hour.

Related Commands

  • Date: Retrieves the current date as a Date object.
  • Time: Retrieves the current time as a time string.
  • TimeValue: Converts a time string to a Date object.