TIME( ) function

Extracts the time from a specified time or datetime and returns it as a character string. Can also return the current operating system time.

Syntax

TIME(<time/datetime> <,format>)

Parameters

time/datetime

Optional. Datetime. The field, expression, or literal value to extract the time from. If this parameter is omitted, the current operating system time is returned in the format hh:mm:ss.

format

Optional. Character. The format to apply to the output string. If this parameter is omitted, the current ACL time display format is used. You cannot specify a format if you have omitted the time/datetime parameter. The format parameter must be enclosed in quotation marks.

Output

Character.

Remarks

The length of the output string is always 14 characters, or 28 characters in the Unicode edition of ACL. If the specified output format, or the ACL time display format, is less than 14 characters (or 28 characters), the output string is padded with trailing blank spaces.

The TIME( ) function, when used without parameters, returns the current operating system time as a character string, whereas the NOW( ) function returns the current operating system time as a datetime value.

A field specified for the time/datetime parameter can use any time or datetime format, as long as the field definition correctly defines the format.

When specifying a literal time or datetime value for the time/datetime parameter, you are restricted to the formats in the table below, and you must enclose the value in backquotes – for example, `20141231 235959`. For datetime values, you can use any combination of date, separator, and time formats. The date must precede the time, and you must use a separator between the two. For time values, you can use any combination of separator and time formats. You must use a separator before the time value for the function to operate correctly. Times must be specified using the 24-hour clock. Offsets from Coordinated Universal Time (UTC) must be prefaced by a plus sign (+) or a minus sign (-). Do not use any separators such as slashes (/) or colons (:) between the individual components of dates or times.

Date formats

Separator formats

Time formats

Examples

YYYYMMDD

single blank space

hhmmss

`20141231 235959`

YYMMDD

the letter ‘t’

hhmm

`141231 2359`

the letter ‘T’

hh

`141231t23`

 

+/-hhmm

(UTC offset)

`141231t235959-0500`

+/-hh

(UTC offset)

`141231T2359+01`

(Note: Do not use hh alone in the main time format with data that has a UTC offset. For example, avoid: hh+hhmm. Results can be unreliable.)

`t235959`

If you use the format parameter to control how the output string is displayed, you are restricted to the formats in the table below. You can use any combination of time and AM/PM formats. The AM/PM format is optional, and is placed last. The format parameter must be specified using single or double quotation marks – for example, "hh:mm:ss AM".

Time formats

AM/PM formats

Examples

hh:mm:ss

none

24-hour clock

"hh:mm:ss"

hhmmss

AM, or PM

12-hour clock

"hhmmss PM"

hh:mm

A, or P

12-hour clock

"hh:mm A"

hhmm

 

hh

Examples

Example Return value

TIME(`20141231 235959`)

235959

Returned as a character string, using the current ACL time display format

TIME(`20141231 235959`, "hh:mm A")

11:59 P

Returned as a character string, using the specified format

TIME( )

The current operating system time returned as a character string in hh:mm:ss format (24-hour clock)

TIME(Receipt_timestamp)

The time returned as a character string for each value in the Receipt_timestamp field, using the current ACL time display format

TIME(Receipt_timestamp, "hh:mm:ss")

The time returned as a character string for each value in the Receipt_timestamp field, using the specified format

Calculating the elapsed time for a command or a script to execute

You can use the TIME( ) function to calculate the amount of time a particular ACL command, or an entire script, takes to execute. Immediately before the command you want to time, or at the start of the script, enter this line to create a variable that stores the current operating system time:

Time_started=TIME( )

Immediately after the command, or at the end of the script, enter the two lines below. The first line creates a variable that stores the operating system time after the command or script completes. The second line calculates the difference between the finish and start times, and converts the result to an easily readable format. You can double-click the CALCULATE log entry to see the elapsed time for the command or the script.

Time_finished=TIME( )

CALCULATE STOT(CTOT(Time_finished) - CTOT(Time_started))

If the command or script will run over the boundary of midnight, use this second line instead:

CALCULATE `T000000` - (CTOT(Time_started) - CTOT(Time_finished))

Related reference
DATE( ) function
DATETIME( ) function
NOW( ) function


(C) 2013 ACL Services Ltd. All Rights Reserved. | Send feedback