Converting text to date/time types

Text values are converted to date/time values when:

Converting text to date

EGL uses the strlib.defaultDateFormat system variable to interpret the text. The conversion algorithm is tolerant of different or missing separators but will take the order of year, month, and day of month from the default format.

If you cannot be sure of the setting of the defaultDateFormat, you can take one of the following steps to make sure that your program always converts the specified values in the same way:
  • Use the dateTimeLib.dateValueFromGregorian() function to convert text values to DATE values. See dateValueFromGregorian().
  • Specify a date format for DATE type input fields.

Converting text to time

EGL uses the strlib.defaultTimeFormat system variable to interpret the text. EGL looks for the fields in order of hours, minutes, and seconds, permitting any separators between them.

If you cannot be sure of the setting of the defaultTimeFormat, you can specify a time format for TIME type input fields to make sure that your program always converts the specified values in the same way.

Converting text to timestamp

EGL uses the strlib.defaultTimestampFormat system variable to interpret the text. If that fails, EGL looks for the timestamp fields in order from largest to smallest, permitting any separators between them.

If you cannot be sure of the setting of the defaultTimestampFormat, you can take one of the following steps to make sure that your program always converts the specified values in the same way:
  • Use the dateTimeLib.timestampValueWithPattern() function to convert text values to TIMESTAMP values.
  • Specify a timestamp format for TIMESTAMP type input fields.

Converting text to interval

EGL performs the conversion for the interval fields in order from largest to smallest, permitting any separators between them. The text may optionally begin with a leading + or -.

Example

Suppose you assign the following string to a DATE variable, and there is no default date pattern:
myDate = "aaa2006aa01a02222aa";
Using the pattern of four digits for the year, followed by two digits each for the month and the day, EGL parses the string into the following groups of digits:
2006  01  02
Finally, EGL returns the complete DATE value:
2006/01/02
However, the non-digit characters are not the only places where EGL separates the digits. In the following case, EGL reaches the maximum number of digits for the first field and then moves digits to the next field in the DATE value:
myDate = "aa20051aa02222aa";
In this case, EGL uses the same pattern of digits for the year, month, and day, but the second group of digits is cut short by a non-digit character. EGL parses the string into the following groups of digits:
2005  1  02
Finally, EGL returns the complete DATE value:
2005/01/02

Feedback