VBScript TimeSerial Function

Definition and Usage

The TimeSerial function can combine hours, minutes, and seconds into a time.

Note:If the hours, minutes, or seconds exceed the appropriate range, the principle of calculation is the same as DateSerial. If the calculated time is less than #00:00:00#, the negative time will be automatically converted to positive time; if the calculated time is greater than or equal to #24:00:00#, the time will be increased forward, making the data become a date and time data with a starting date of #12/30/1899#.

Syntax

TimeSerial(hour,minute,second)
Parameter Description
hour Required. A number between 0-23, or a numerical expression.
minute Required. A number between 0-59, or a numerical expression.
second Required. A number between 0-59, or a numerical expression.

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

When any parameter value exceeds the acceptable range, it will correctly roll over to the next larger time unit. For example, if 75 minutes are specified, the time is interpreted as 1 hour and 15 minutes. However, if any parameter value exceeds the range of -32768 to 32767, an error will occur. If the time specified by three parameters directly or calculated by an expression exceeds the acceptable date range, an error will also occur.

Instance

Example 1

document.write(TimeSerial(9,30,50)) 'Normal calling method'

Output:

9:30:50 AM or 9:30:50 PM

Example 2

document.write(TimeSerial(0,9,11)) 'Normal calling method'

Output:

12:09:11 AM or 0:09:11 AM

Example 3

document.write(TimeSerial(14+2,9-2,1-1)) 'Output time based on the result of the numerical expression'

Output:

4:07:00 PM or 8:07:00 AM

Example 4

document.write(TimeSerial(26,30,0)) 'The date starts from #12/30/1899# and increases by 1 day'

Output:

1899-12-31 2:30:00 AM