Syntax 2: For strings – PB Docs 2017

Syntax 2: For strings

Description

Converts a string whose value is a valid date to a date
value.

Syntax

Argument

Description

string

A string containing a valid date (such as January
1, 2002, or 12-31-99) that you want returned as a date.
Datetime can also be an Any variable containing a
string.

Return value

Date.

Returns the date in string as a date. If string contains an
invalid date or an incompatible datatype, Date returns 1900-01-01. If
string is null, Date returns null.

Usage

Valid dates in strings can include any combination of day (1 to
31), month (1 to 12 or the name or abbreviation of a month), and year (2
or 4 digits). PowerBuilder assumes a 4-digit number is a year. Leading
zeros are optional for month and day. The month, whether a name, an
abbreviation, or a number, must be in the month location specified in
the system setting for a date’s format. If you do not know the system
setting, use the standard datatype date format yyyy-mm-dd.

PowerBuilder attempts to match the input string to a date format
in the regional settings on the computer. If a complete match is not
found, PowerBuilder attempts a partial match. For example, if you use
Date(’01-JAN-1900′) and PowerBuilder finds the partial match
(dd-MMM-yy), PowerBuilder parses the first two numbers of the year and
gets 19. The 2-digit year is interpreted as a year between 1930 and
2029, and the date returned is 1/1/2019.

Date literals do not need to be converted with the Date
function.

Examples

Example 1

These statements all return the date datatype for text expressing
the date July 4, 2004 (2004-07-04). The system setting for a date’s
format is set with the month’s position in the middle:

Example 2

The following groups of statements check to be sure the date in
sle_start_date is a valid date and display a message if it is not. The
first version checks the result of the Date function to see if the date
was valid. The second uses the IsDate function to check the text before
using Date to convert it:

Version 1:

Version 2:

See also

DateTime

IsDate

RelativeDate

RelativeTime

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


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x