MS Access: TimeValue Function
This MSAccess tutorial explains how to use the Access TimeValue function with syntax and examples.
Description
The Microsoft Access TimeValue function converts a string to a time.
Syntax
The syntax for the TimeValue function is in MS Access:
TimeValue ( string_time )
Parameters or Arguments
- string_time
- A string representation of a time. string_time can be a time ranging from 0:00:00 to 23:59:59. string_time can be entered in either 12-hour or 24-hour clock notation.
Returns
The TimeValue function returns a time value.
Applies To
The TimeValue function can be used in the following versions of Microsoft Access:
- Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
Example
Let's look at how to use the TimeValue function in MS Access:
TimeValue ("3:12:57 PM") Result: 3:12:57 PM TimeValue ("15:12:57") Result: 3:12:57 PM
Example in VBA Code
The TimeValue function can be used in VBA code in Microsoft Access.
For example:
Dim LTime As Date LTime = TimeValue ("18:30:12")
In this example, the variable called LTime would now contain the value of 6:30:12 PM.
Example in SQL/Queries
You can also use the TimeValue function in a query in Microsoft Access.
For example:
In this query, we have used the TimeValue function as follows:
Expr1: TimeValue("5:59:58")
This query will take a string representation of "5:59:58" and return its time value in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.
For example:
NewTime: TimeValue("5:59:58")
The results would now be displayed in a column called NewTime.
Advertisements