You are here: System Setup > Attributes > Calculated Attributes > Date Functions

Date Functions

Calculated Attribute expressions can be written using the following available functions. Examples follow the Available Functions table.

Available Functions

Date Function

Parameters

Description

FORMATDATETIME

(date, format-string[, locale])

Determine the output by formatting a date according to the format-string, see documentation for SimpleDateFormat for Oracle on the web.

[locale] is optional; see Using a Locale below

LOCALIZEDATE

(date[, locale])

Localize the date to a string using the locale in the current / extracting / resolving context, or using the supplied locale.

[locale] is optional; see Using a Locale below

NOW

()

Returns current time on server in yyyy-MM-dd HH:mm:ss format.

Note: The above functions work only when the date values are entered in yyyy- MM- dd or yyyy- MM- dd HH:mm:ss formats. 'ISO Date' and 'ISO Date and Time' validation base type attributes accept only these formats.

Using a Locale

To obtain a date or date / time format for a specific locale, in order to override the locale that is specified by the current context, enter the locale's ID and ensure the following property is defined in the sharedconfig.properties file: Calculated.UseLegacyLocalization=true

For more information on locales, see Context Locales documentation in this guide here.

Examples

AttrDateID on Product

Value

P1id

2016-10-15

P2id

1997-12-25

P3id

2016-05-15

Copy and paste any of the following examples into the Function Editor and then evaluate against the specified object to get the defined result.

formatdatetime(prodval('AttrDateid'), "EEE, MMM d, ''yy") // = "Fri, Oct 15, '16" for P1id
formatdatetime(prodval('AttrDateid'), "yyyyy.MMMMM.dd" ) // = "01997.December.25" for P2id
formatdatetime(prodval('AttrDateid'), "MMM d, yy" ) // = "May 15, 16" for P3id
localizedate(prodval('AttrDateid')) // = "15-05-2016" for P3id when in Danish context
now() // = "2016-05-04 12:06:25" when executed on 4 MAY 2016 just after midday
 

The StartDate attribute is of the 'ISO Date' validation base type, and has the value: 2017-03-13. The following calculated attribute function returns the localized values displayed below for Great Britain, United States, and Germany.

{d := value('StartDate'), x := localizedate(d, "en_GB"), y := localizedate(d, "en_US"), 
z := localizedate(d, "de_DE")} concatenate(d, "   ", x, "   ", y, "   ", z) 
// 2017-03-13   13-Mar-2017  Mar 13, 2017  13.03.2017

2017, Stibo Systems