util.Datetime.parse() converts a string into a DATETIME value according to the specified format.
Syntax
util.Datetime.parse(string, format)
Parameters
string |
the source string than must be parsed (STRING) |
format |
Usage and examples
util.Datetime.parse() takes a string and converts it into a DATETIME value according to the specified format:
DISPLAY util.Datetime.parse("2017-02-22 14:15", "%Y-%m-%d %H:%M")
A format string must be a combination of placeholders representing different parts of a DATETIME value (year, month, day, hour, minute, second, and fraction).
You can learn about these placeholders here.
The precision of the resulting DATETIME value depends on the specified format: E.g., if you use the format string "%y-%m-%d", the resulting value will be a DATETIME YEAR TO DAY.
util.Datetime.parse() will return NULL if the source string cannot be converted to a DATETIME value according to the specified format.
example code |
MAIN DEFINE dt_ym DATETIME YEAR TO MINUTE, dt_yd DATETIME YEAR TO DAY, dt_yy DATETIME YEAR TO YEAR LET dt_ym= util.Datetime.parse("2017-02-22 14:15", "%Y-%m-%d %H:%M") DISPLAY dt_ym LET dt_yd = util.Datetime.parse("2017-02-22", "%Y-%m-%d") DISPLAY dt_yd LET dt_yy= util.Datetime.parse("2017", "%Y") DISPLAY dt_yy CALL fgl_getkey() END MAIN |
obtained results |
|