TimeValue Function

Purpose

Returns a value containing the time.

Syntax

var = TimeValue(exp)

var: variable
exp: aexp

Description

This function converts exp and returns a time value in var. The conversion uses the VarDateFromString API and so takes into account the Regional settings of the system rather than the current GB Mode setting (for a GB Mode compliant function, see ValDate).

The expression exp can be a string, date, or date literal. If there is a date element then any date literal must use a period (or full stop) separator for date (25.12.2018 12:54) regardless of Mode settings.

The value returned to var depends on the variable type for the return value but is Date by default: when var is a Single or Double a decimal representation of the time element is returned; if var is a String, the time is returned as a string. If var is an integer then 0 (upto 12:00) or 1 (after 12:00) will be returned.

Example

Local da As Date, db As Double, i As Int, s As String

da = TimeValue("25 Jan 2019 11:42") : Print da  // 11:42:00

db = TimeValue("25 Jan 2019 11:42") : Print db  // 0.4875

i = TimeValue("25 Jan 2019 11:42") : Print i    // 0 - Upto 12:00

s = TimeValue("25 Jan 2019 11:42") : Print s    // 11:42:00

Print TimeValue(#25.01.2019 11:42:00#)          // 11:42:00

Print VarType(TimeValue(#25.01.2019 11:42:00#)) // 7 = Date

This example uses the DateTime function to convert a string to a date.

Dim X As Date, Y As Double

X = TimeValue(Now)

Y = TimeValue(Now)

Print X, Y, TimeValue(Now)

Print TimeValue(FileDateTime(ProgName))

See Also

CDate(), Date, Date$, DateAdd(), DateDiff(), DatePart(), DateSerial(), DateTime$(), DateToDmy, DateToDmyHms, DateValue(), Day(), DayNo(), DmyHmsToDate(), DmyToDate(), HmsToTime(), Hour(), IsDate(), Minute(), Month(), Now, Now$(), TimeSerial(), TimeToHms, TimeValue(), Second(), Week(), WeekDay(), Year()

{Created by Sjouke Hamstra; Last updated: 02/02/2019 by James Gaite}