DateTime

Manipulates DateTime values. There are three syntaxes.

To

Use

Combine a date and a time value into a DateTime value

Syntax 1

Obtain a DateTime value that is stored in a blob

Syntax 2

Obtain a DateTime value that is stored in a string

Syntax 3


Syntax 1: For creating DateTime values

Description

Combines a date value and a time value into a DateTime value.

Syntax

DateTime ( date {, time } )

Argument

Description

date

A value of type date.

time (optional)

A value of type time. If you omit time, PowerBuilder sets time to 00:00:00.000000 (midnight). If you specify time, only the hour portion is required.


Return value

DateTime.

Returns a DateTime value based on the values in date and optionally time. If any argument's value is null, DateTime returns null.

Usage

DateTime data is used only for reading and writing DateTime values to and from a database. To use the date and time values in scripts, use the Date and Time functions to assign values to date and time variables.

Examples

These statements convert the date and time stored in ld_OrderDate and lt_OrderTime to a DateTime value that can be used to update the database:

DateTime ldt_OrderDateTime
date ld_OrderDate
time lt_OrderTime
 
ld_OrderDate = Date(sle_orderdate.Text)
lt_OrderTime = Time(sle_ordertime.Text)
ldt_OrderDateTime = DateTime( &
    ld_OrderDate, lt_OrderTime)

See also

Date

Time

DateTime method for DataWindows in the section called “DateTime” in DataWindow Reference

Syntax 2: For extracting DateTime values from blobs

Description

Extracts a DateTime value from a blob.

Syntax

DateTime ( blob )

Argument

Description

blob

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


Return value

DateTime.

Returns the DateTime value stored in blob. If blob is null, DateTime returns null.

Usage

DateTime data is used only for reading and writing DateTime values to and from a database. To use the date and time values in scripts, use the Date and Time functions to assign values to date and time variables.

Examples

After assigning blob data from the database to lb_blob, the following example obtains the DateTime value stored at position 20 in the blob (the length you specify for BlobMid must be at least as long as the DateTime value but can be longer):

DateTime dt
dt = DateTime(BlobMid(lb_blob, 20, 40))

See also

Date

Time

Syntax 3: For extracting DateTime values from strings

Description

Extracts a DateTime value from a string whose value is valid datetime.

Syntax

DateTime ( string )

Argument

Description

string

A string containing a valid datetime.


Return value

DateTime.

Returns the DateTime value stored in the string. If string does not contain a valid datetime, DateTime returns null.

Usage

DateTime data is used only for reading and writing DateTime values to and from a database. To use the date and time values in scripts, use the Date and Time functions to assign values to date and time variables.

To make sure you get correct return values for the year, you must verify that yyyy is the Short Date Style for year in the Regional Settings of the user's Control Panel. Your program can check this with the RegistryGet function. If the setting is not correct, you can ask the user to change it manually or to have the application change it (by calling the RegistrySet function). The user might need to reboot the computer after the setting is changed.

Examples

The following example converts the date and time stored in a string to the datetime July 23, 2019 (2019-07-23) 13:25:59.

DateTime dt
dt = DateTime('2019/7/23 13:25:59')
//dt = DateTime('2019 July 23 13:25:59')

See also

Date

Time