Time

Converts DateTime, string, or numeric data to data of type time. It also extracts a time value from a blob. You can use one of three syntaxes, depending on the datatype of the source data.

To

Use

Extract the time from DateTime data, or to extract a time stored in a blob

Syntax 1

Convert a string to a time

Syntax 2

Combine numbers for hours, minutes, and seconds into a time value

Syntax 3


Syntax 1: For DateTime and blob values

Description

Extracts a time value from a DateTime value or a blob.

Syntax

Time ( datetime )

Argument

Description

datetime

A DateTime value or a blob in which the first value is a time or DateTime value. The rest of the contents of the blob is ignored.  Datetime can also be an Any variable containing a DateTime or blob.


Return value

Time.

Returns the time in datetime as a time. If datetime does not contain a valid time or is an incompatible datatype, Time returns 00:00:00.000000. If  datetime is null, Time returns null.

Examples

After StartDateTime has been retrieved from the database, this example sets StartTime equal to the time in StartDateTime:

DateTime StartDateTime
time StartTime
... 
StartTime = Time(StartDateTime)

Suppose that the value of a blob variable ib_blob contains a DateTime value beginning at byte 32. The following statement extracts the time from the value:

time lt_time
lt_time = Time(BlobMid(ib_blob, 32))

See also

Time method for DataWindows in the section called “Time” in DataWindow Reference.

Syntax 2: For strings

Description

Converts a string containing a valid time into a time value.

Syntax

Time ( string )

Argument

Description

string

A string whose value is a valid time (such as 8am or 10:25) that you want returned as a time. Only the hour is required; you do not have to include the minutes, seconds, or microseconds of the time or am or pm.

The default value is 00 for minutes and seconds and 000000 for microseconds. PowerBuilder determines whether the time is am or pm based on a 24-hour clock.

String can also be an Any variable containing a string or blob.


Return value

Time.

Returns the time in string as a time. If string does not contain a valid time or is an incompatible datatype, Time returns 00:00:00.000000. If string is null, Time returns null.

Usage

Valid times can include any combination of hours (00 to 23), minutes (00 to 59), seconds (00 to 59), and microseconds (0 to 999999).

Examples

These statements set What_Time to null:

Time What_Time
string null_string
 
SetNull(null_string)
What_Time = Time(null_string)

This statement returns a time value for 45 seconds before midnight (23:59:15), which is specified as a string:

Time("23:59:15")

This statement converts the text in the SingleLineEdit sle_Time_Received to a time value:

Time(sle_Time_Received.Text)

See also

Time method for DataWindows in the section called “Time” in DataWindow Reference.

Syntax 3: For integers

Description

Combines integers representing hours, minutes, seconds, and microseconds into a time value.

Syntax

Time ( hour, minute, second {, microsecond } )

Argument

Description

hour

The integer for the hour (00 to 23) of the time

minute

The integer for the minutes (00 to 59) of the time

second

The integer for the seconds (0 to 59) of the time

microsecond (optional)

The integer for the microseconds (0 to 32767) of the time (note that the range of values supported for this argument is less than the total range of values possible for a microsecond)


Return value

Time.

Returns the time as a time datatype and 00:00:00 if the value in any argument is not valid (out of the specified range of values). If any argument is null, Time returns null.

Examples

These statements set What_Time to a time value with microseconds, and display the resulting time as a string in st_1. The default display format does not include microseconds, so the String function specifies a display format with microseconds. Leading zeros are appended to the string value for microseconds:

Time What_Time
What_Time = Time(10, 15, 45, 234)
st_1.Text = String(What_Time, "hh:mm:ss.ffffff")

The time in the string variable is set to 10:15:45.000234.

These statements set What_Time to 10:15:45:

Time What_Time
What_Time = Time(10, 15, 45)

See also

Time method for DataWindows in the section called “Time” in DataWindow Reference.