Applies ToAccess for Microsoft 365 Access 2024 Access 2021 Access 2019 Access 2016

Returns a Variant (Date) containing the time.

Syntax

TimeValue ( time )

The required timeargument is normally a string expression representing a time from 0:00:00 (12:00:00 A.M.) to 23:59:59 (11:59:59 P.M.), inclusive. However, time can also be any expression that represents a time in that range. If time contains Null, Null is returned.

Remarks

You can enter valid times using a 12-hour or 24-hour clock. For example, "2:24PM" and "14:24" are both valid time arguments.

If the time argument contains date information, TimeValue doesn't return it. However, if time includes invalid date information, an error occurs.

Query examples

Expression

Results

SELECT TimeValue([DateTime]) AS Expr1 FROM ProductSales;

Returns the time values of the field "DateTime" without the date information and displays in the column Expr1.

SELECT TimeValue([DateTime]) AS JustTime FROM ProductSales;

Returns the time values of the field "DateTime" without the date information and displays in the column JustTime.

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 TimeValue function to convert a string to a time. You can also use date literals to directly assign a time to a Variant or Date variable, for example, MyTime = #4:35:17 PM#.

Dim MyTimeMyTime = TimeValue("4:35:17 PM")    ' Return a time.

Choose the right date function

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.