Date Functions

Table 50. Date Functions

Function

Description

dateadd

Returns a date after adding (or subtracting) the specified units to the date_value.

Syntax: date_var = dateadd(date_value, units_value, quantity_value)

  • date_value = date variable or expression

  • units_value = text literal, column, variable, or expression. Valid units are 'year', 'quarter', 'week', 'month', 'day', 'hour', 'minute', and 'second'

  • quantity_value = decimal, float, or integer literal, column, variable, or expression. The value is always converted to float.

  • date_var = date variable

Example: let $date = dateadd($startdate, 'day', 7.5)

datediff

Returns the difference between the specified dates expressed in units_value. The function returns a float value. The result can be negative if the first date is earlier than the second date.

Syntax: dst_var = datediff(date1_value, date2_value, units_value)

  • date1_value = date variable or expression

  • date2_value = date variable or expression

  • units_value = text literal, column, variable, or expression. Valid units are 'year', 'quarter', 'week', 'month', 'day', 'hour', 'minute', and 'second'

  • dst_var = decimal, float, or integer variable

Example: let #diff = datediff($date1, $date2, 'hour')

datenow

Returns the current local date and time from the client machine.

Syntax: dst_var = datenow()

  • dst_var = date variable

Example: let $date = datenow()

datetostr

Converts the date date_value to a string in the format format_mask.

Syntax: dst_var = datetostr(date_value, [format_mask])

  • date_value = date variable or expression

  • format_mask = text literal, column, variable, or expression. DATE can be used to specify DATE‑EDIT‑MASK from the current locale. If this argument is not specified, then the format specified by SQR_DB_DATE_FORMAT is used. If this has not been set, then the first database-dependent format in Table 61, Default Formats by Database is used.

  • dst_var = text variable

Example: let $formdate = datetostr($date, 'Day Mon DD, YYYY') let $localedate = datetostr($date, DATE)

strtodate

Converts the string source_value in the format format_mask to a date type.

Syntax: dst_var = strtodate(source_value [, format_mask])

  • source_value = text literal, column, variable, or expression

  • format_mask = text literal, column, variable, or expression that describes the exact format of the source_value. DATE can specify the DATE‑EDIT‑MASK setting from the current locale. If not specified, then source_value must be in the format specified by SQR_DB_DATE_FORMAT, one of the database-dependent formats (see Table 61, Default Formats by Database), or the database-independent format 'SYYYYMDD[HH24[MI[SS[NNNNNN]]]]'. Valid format codes are specified in Table 57, Date Edit Format Characters. See PRINT for information regarding the default date-time components as a result of converting an incomplete date.

  • dst_var = date variable

Example: let $date = strtodate($str_date, 'Mon DD, YYYY') let $date = strtodate($str_date, DATE)