util.Datetime.parse

Converts a string to a DATETIME value based on a specified format.

Syntax

util.Datetime.parse(
  s STRING,
  format STRING
)
  RETURNS DATETIME q1 TO q2
  1. s is the source string to be parsed.
  2. format is the format specification (see Formatting DATETIME values).

Usage

The util.Datetime.parse() method parses a string based on a format specification, to produce a DATETIME value.

Note: The parse() method produces a DATETIME value. However, since Genero BDL supports implicit type conversion, it is possible to assign a DATE variable with the value returned from parse(), as long as the DATETIME contains a date part.

The format specification must be a combination of place holders such as %Y, %m, %d, etc.

The precision of the resulting DATETIME value depends on the format specification. For example, when using "%Y-%m-%d %H:%M", the resulting value will be a DATETIME YEAR TO MINUTE.

The method returns NULL, if the source string cannot be converted to a DATETIME value based on the format specification.

For more details about the supported formats, see Formatting DATETIME values.

Example

IMPORT util
MAIN
    DEFINE dt DATETIME YEAR TO MINUTE
    LET dt = util.Datetime.parse( "2014-12-24 23:45", "%Y-%m-%d %H:%M" )
    DISPLAY dt
END MAIN