$date

Return the current date or convert the argument to the Date data type.

$date { (Source) }

Parameters

Parameters
Parameter Data Type Description
Source String String to be converted to Date data type.

Return Values

The function $date returns the following:

  • If Source is omitted or is an empty string (""), $date returns the current system date.
  • If Source is present, $date converts it to data type Date and returns that value.
  • If Source cannot be converted to a Date value (for example, $date("abc")), $date returns an empty string ("").
  • If a service or report component is running in a remote environment, the function $date returns the system time of the server (not of the client).

If an error occurs, $procerror contains a negative value that identifies the exact error.

Values Commonly Returned by $procerror after $date
Value Error Constant Meaning
-1004 <UPROCERR_DATE> Not a valid Date value.

Use

Allowed in all component types.

Description

The $date function scans Source from left to right for valid characters. Valid characters depend on locale as determined by the values $nlslocale and $nlsformat:

  • classic—Uniface is very tolerant towards the input string and tries to convert the string to a valid date.
  • nlslocale—strict rules apply:
    • The input string must be in the exact display format of a date in the selected locale. To find out the required format, check the output without an input string or using an empty string: $date or $date("").
    • From the point where the input string does not comply with the syntax for the selected locale, the return value is completed with values derived from the current date.
    • If the first characters of the input string do not comply with the syntax for the selected locale, an empty string is returned.
Syntax Format for Selected Locales
Locale Syntax
Classic dd-mmm-yyyy
En_US mmmdd, yyyy
de_DE dd.mm.yyyy
nl_NL ddmmmyyyy

The following table shows the effect that the locale can have on the way an input string is converted. Remember that from the point where the input string does not comply with the syntax for the selected locale, the return value is completed with values derived from the current date.

  • Classic: $nlsformat="classic" or $nlslocale="classic"
  • United States: $nlsformat="nlslocale" and $nlslocale="en_US"
  • Germany: $nlsformat="nlslocale" and $nlslocale="de_DE"
  • Netherlands: $nlsformat="nlslocale" and $nlslocale="nl_NL"
Examples Assuming May 21, 2019 is the Current Date
Source Classic United States Germany Netherlands
"" 21-may-2019 May 21, 2019 21.05.2019 21 mei 2019
"CLEAR" "" "" "" ""
"20190521" 21-may-2019 May 21, 2019 21.05.2019 21 mei 2019
21-may-2019 21-may-2019 "" 21.05.2019 21 mei 2019
May 21,2019 "" May 21, 2019 "" ""
May 21, 2019 "" May 21, 2019 "" ""
21.05.2019 21-may-2019 "" 21.05.2019 21 mei 2019
21-mei-2019 21-may-2019 "" 21.05.2019 21 mei 2019
21 mei 2019 21-may-2019 "" 21.05.2019 21 mei 2019

Default Date Format

If $nlsformat or $nlslocale is set to classic, the conversion process is governed by the format of the default date format. If Source has a different format from the default date format, you must convert it into one that Uniface can work with. In this case, you can either change the default so that the default reflects the data, or change the data so that the data reflects the default.

To change the default, you need to change the $language and $variation codes to select a language setup with a default date format that is the same as the string argument. Then use $date to convert the value.

To change the data, you can define a global or component variable with the appropriate display format. For example, if you have a default date format of dd-mmm-yyyy, and you have retrieved date information in the format mm/dd/-/, you should define a global or component variable with a display format of DIS(mm/dd/yyyy); then copy the retrieved date to this variable. This ensures that Uniface correctly interprets the value of the retrieved date. (This also avoids the use of $date.)

Note:  The conversion process is governed by the format of the default date. To define the default date in the Deployment Workspace, choose Tools >Language Setups >Date-time Properties. The default language setup used by an application is governed by the values of $language and $variation.

Using $date

The following examples show the different values returned by $date. The value returned depends on the default date in the language setup. The first example has a default date format of dd-mmm-yyyy , and the example code was tested on the 21st of August, 1994:

clrmess
$1 = $date("1-2-94")
putmess "$1 = %%$1 on value of 1-2-94"
$2 = $date
putmess "$2 = %%$2 on value of null"

This produces the following message frame:

$1 = 01-feb-1994 on value of 1-2-94
$2 = 21-aug-1994 on value of null

When exactly the same code was run, but with a default language setting of mmm-dd-yyy , the following message frame was generated:

$1 = jan-02-1994 on value of 1-2-94
$2 = aug-21-1994 on value of null
History
Version Change
9.4.01 Additional option for overriding the default behavior if the time zone has been defined (using $nlstimezone or $NLS_TIME_ZONE)

Related Topics