create and format date()

This function parses a text a using template b and creates a timestamp from these values. The timestamp will then be formatted to a text using template c.

If e is set to "true", no parsing and no conversion will take place and the function returns an empty string.

Parameters


Parameter

Description

a

The text to be interpreted. If a string cannot be interpreted with the format template b, an error occurs and parameter d controls the further behaviour of the function.

b

(optional) Format template to be used to convert the text in a into a timestamp. The parameter must be left empty if a date or a timestamp is used in parameter a. Default: "yyyy-MM-dd HH:mm:ss.SSS". Important note: If the string in a is shorter than the template in b, b is shortened to the length of a. Please note that in rare cases this can lead to loss of accuracy or invalid values and consequential errors. Special case: There is no shortening for W3CDTF.

c

Format template to generate a text out of the created timestamp.

d

(optional) Behaviour if an error occurs. See possible values in the table below. Default: "empty".

e

(optional) If "true", not parsing and no conversion takes place and the result of the function will be an empty string. Default: "false".

Note: Parameter e can be used for the following scenario. Often (for example, in SAP IDocs), the date and time values are transferred in separate fields. If only both values together are regarded as a valid value, you can use function "empty()" to determine whether one of the fields is empty and then (if that is the case) force the result of the conversion to be an empty string.

Possible values for parameter "d"


Value

Behaviour of function

now

The current date will be used as input value.

empty

A string of length 0 ("") will be returned. In addition to that, the Empty Flag is set.

error

Terminates the function with an error.

Other value

Instead of the input value a, this value will be used. If it cannot be interpreted using format template c, the function aborts with an error.

Examples


Current date of the example: "2011-10-20 15:33:23.0".


Parameter a

Parameter b

Parameter c

Parameter d

Parameter e

Result

01.10.11 23:34:56

dd.MM.yy HH:mm:ss

MM/dd/yyyy HH:mm:ss

error


10/01/2011 11:34:56 PM

01.10.11 23:34:56

dd.MM.yy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

error


10/01/2011 12:00:00 AM

01.10.11

dd.MM.yy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

error

true

The function terminates with an error. The value in parameter a could be successfully parsed, as you can see in the previous example but parameter e forces the function to interpret parameter a as being empty. Therefore, the action defined in parameter d is executed.

01.10.11

dd.MM.yy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

error



No date

dd.MM.yyyy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

error


The function terminates with an error.

No date

dd.MM.yyyy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

now


10/20/2011 03:33:23 PM

No date

dd.MM.yyyy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

empty


String of length 0 ("") and set Empty Flag.

No date

dd.MM.yyyy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

12/15/2011 11:54:12 AM


12/15/2011 11:54:12 AM

No date

dd.MM.yyyy HH:mm:ss

MM/dd/yyyy hh:mm:ss a

No date either


Function terminates with an error.

1997-07-16T19:20:30Z

W3CDTF

dd.MM.yyyy HH:mm:ss

empty


16.07.1997 21:20:30

01.10.11 23:34:56

dd.MM.yy HH:mm:ss

W3C

error


2011-10-01T21:34:56Z (always UTC)