Monday, June 27, 2022

TimeSerial Function [MS]

Returns a Variant (Date) containing the time for a specific hour, minute, and second.


TimeSerial ( hour, minute, second )

Warning    Make sure the arguments are in the correct range of values. An invalid argument can result in an incorrect result.

The TimeSerial function syntax has these arguments:




Required. Variant (Integer). Number between 0 (12:00 A.M.) and 23 (11:00 P.M.), inclusive, or a numeric expression.


Required. Variant (Integer). Any numeric expression.


Required. Variant (Integer). Any numeric expression.


To specify a time, such as 11:59:59, the range of numbers for each TimeSerial argument should be in the normal range for the unit; that is, 0–23 for hours and 0–59 for minutes and seconds. However, you can also specify relative times for each argument using any numeric expression that represents some number of hours, minutes, or seconds before or after a certain time. The following example uses expressions instead of absolute time numbers. The TimeSerial function returns a time for 15 minutes before (-15) six hours before noon (12 - 6), or 5:45:00 A.M.

TimeSerial(12 - 6, -15, 0)

When any argument exceeds the normal range for that argument, it increments to the next larger unit as appropriate. For example, if you specify 75 minutes, it is evaluated as one hour and 15 minutes. If any single argument is outside the range -32,768 to 32,767, an error occurs. If the time specified by the three arguments causes the date to fall outside the acceptable range of dates, an error occurs.

Query example



SELECT TimeSerial(18,12,10) AS NewTime FROM ProductSales GROUP BY TimeSerial(18,12,10);

Returns the "Time" made up of specified hour, minute, and second entered in the arguments of the function and displays in the column NewTime. Result: "6:12:10 PM".

VBA example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the TimeSerial function to return a time for the specified hour, minute, and second.

Dim MyTime
MyTime = TimeSerial(16, 35, 17)
' MyTime contains serial representation of 4:35:17 PM.

Choose the right date function

No comments:

Post a Comment

Search This Blog

Work with photos in a SharePoint picture library [MS]

SharePoint Documents and Libraries Manage ...