Functions
In addition to variable methods, there are a handful of stand-alone functions. Stand-alone functions do not require an existing variable and may be placed anywhere a string or numeric expression is allowed. For example, the random function will produce a random value as in “Your wait time is approximately {random(10)} minutes”.
The following table lists all functions available within NG:
Function Name | Description |
---|---|
cos(value) | Returns the cosine of the specified value. The value must be in radians. |
sin(value) | Returns the sine of the specified value. The value must be in radians. |
tan(value) | Returns the tangent of the specified value. The value must be in radians. |
atan(value) | Returns the angle in radians whose tangent is the specified value. |
atan2(x, y) | Returns the angle in radians whose tangent is the quotient of the two specified numbers. |
acos(value) | Returns the angle in radians whose cosine is the specified value. |
asin(value) | Returns the angle in radians whose sine is the specified value. |
cosh(value) | Returns the hyperbolic cosine of the specified value. The value must be in radians. |
sinh(value) | Returns the hyperbolic sine of the specified value. The value must be in radians. |
tanh(value) | Returns the hyperbolic tangent of the specified value. The value must be in radians. |
exp(value) | Returns the number raised to the power specified in value. |
ln(value) | Returns the natural (base e) logarithm of the value. The value is specified as a base 10 number. |
log10(value) | Returns the base 10 logarithm of the specified value. |
log2(value) | Returns the base 2 logarithm of the specified value. The value is specified as a base 10 number. |
logn(value, base) | Returns the logarithm of the specified value in the specified base. Both parameters are specified as base 10 numbers. |
sqrt(value) | Returns the square root of the specified value. |
abs(value) | Returns the absolute value of the specified value. |
trunc(value) | Calculates the integral part of the specified value. Trunc rounds value to the nearest integer towards zero. |
round(value) | Returns the value rounded to the nearest integer using IEEE Standard 754, section 4 – sometimes called banker’s rounding. |
floor(value) | Returns the largest integer less than or equal to the specified value. |
ceil(value) | Returns the smallest integer greater than or equal to the specified value. |
random(value) | Returns an integer nonnegative random number greater than or equal to zero and less than the specified maximum value. |
sgn(value) | Returns a value indicating the sign of the specified value. Returns -1 if value is less than zero, 0 if value is equal to zero, and 1 if value is greater than zero. |
min(value1, value2) | Returns the smaller of the two values specified. |
max(value1, value2) | Returns the larger of the two values specified. |
datediff(unit, date1, date2) |
Calculates the difference between two dates and returns the number of units specified. Possible choices for unit are: week, day, hour, minute, and second. Enclose the unit in double or single quotes, or pass a variable which contains the unit name. The unit name is case sensitive. Each date must be specified using the date/time prefix followed by a valid string representation of a date, or it must be an OLE automation date/time. If date2 is greater than date1, the result will be positive. This number might include whole and fractional units. Example: datediff(“hour”, #”4:30 PM”, #”2:00 PM”) Returns: -2.5 |
dateadd(unit, date, value) |
Adds the specified number of units to the given date and returns a new date as an OLE automation date/time. Possible choices for unit are: year, month, week, day, hour, minute, and second. Enclose the unit in double or single quotes, or pass a variable which contains the unit name. The unit name is case sensitive. The date must be specified using the date/time prefix followed by a valid string representation of a date, or it must be an OLE automation date/time. The value may be fractional. Example: {dateadd("minute",#"4:30 PM",2.5).astime} Returns: 4:32:30 PM |
dateparse(datestr) |
Converts the specified date string to an OLE automation date/time. If the datestr cannot be converted, the return is 0. Example: {dateparse("14:30").astime} Returns: 2:30:00 PM |
datefmt(date, format) |
Formats the date using the specified format string. The date must be specified using the date/time prefix followed by a valid string representation of a date, or it must be an OLE automation date/time. See the section titled "Format Specifiers". Example: {datefmt(now, "yyyy-MMM-d, h:mm")} Returns: 2009-Oct-14, 11:48 |
datepart(unit, date) |
Returns a portion of the date or time. The date must be specified using the date/time prefix followed by a valid string representation of a date, or it must be an OLE automation date/time. The unit specifies the date part to return. Possible choices for unit are: year, month, day, hour, minute, second, and dow. Enclose the unit in double or single quotes, or pass a variable which contains the unit name. The unit name is case sensitive. [String expression] Returns the string representation of the specified date part. Month returns the 3 character month abbreviation. Year returns the full 4 digit year. Hour returns the hour in 24 hour format. All numeric values, except year, are prefixed with a 0 if there are less than two digits. Dow stands for Day of Week and is returned as the full string representation of the week day, unabbreviated. [Numeric expression] Returns the numeric representation of the specified date part. Year returns the full 4 digit year. Hour returns the hour in 24 hour format. Dow stands for Day of Week and is returned as the ordinal value for the week day where Sunday is 0. Example: ASSIGN dy=#"11/5/08 6:00PM" ASSIGN dp=datepart("year", dy) |
datebuild(year, month, day) |
[String expression] Returns a date formatted in standard date/time format. [Numeric expression] Returns a date as an OLE automation date/time. |
datetimebuild(year, month, day, hour, minute, second) |
[String expression] Returns a date/time formatted in standard date/time format. [Numeric expression] Returns a date/time as an OLE automation date/time. |
char(code) |
Returns a character from the ASCII code value. This allows a script the ability to programmatically add special characters to a string – such as carriage returns and tabs. Be cautious with this function as char(0) through char(7) are reserved for internal use and MAY cause scripts to malfunction. |
iif(compare,trueval,falseval) |
Inline-If – returns either trueval or falseval depending on the value of compare. If compare is non-zero (true), the trueval will be returned. If compare is zero (false), the falseval will be returned. Both trueval and falseval must be numeric values or expressions. Strings cannot be used. See also iifs. |
iifs(compare, truestr, falsestr) |
String Inline-If – returns either truestr or falsestr depending on the value of compare. If compare is non-zero (true), the truestr will be returned. If compare is zero (false), the falsestr will be returned. This function is identical to iif except it expects strings and returns a string. |
now | This function returns the time on the current business unit. Modifications to the time, such as through the TIMEZONE action, affect the value returned by this function. |
savetodb |
In a snippet you can set the savetodb property for a variable. For example, Assign variable='123123123' variable.savetodb(1) |