40 users using DBSP now!
home -> documentation -> Functions


Description

Functions are a set of operations already defined. Each function could receive no arguments, one or more arguments but it always will return a value. The value returned could be of type string, integer, float or boolean.


Syntax

<#EXPVAL EXPRESSION="FUNCTION(ARGS)"/>
or
<#SETCOOKIE EXPRESSION="FUNCTION(ARGS)"/>
or
<#IF EXPRESSION="FUNCTION(ARGS)"/>

Args The arguments order and types depends directly of each function and any argument could be the result of another function.

Functions set

Integer TRUNC() , CEIL() , FLOOR() , ROUND() , LEN() , RANDOM() , ABS().
Float PI() , ABS() , FRAC() , RANDOM() , LN() , LOGN() , SIN() , COS() , TAN() .
String SUBSTR() , NOW() .
DateTime NOW() , DATEADD() , DATEDIFF() .

References

EXPRESSION


 

Trunc(float)

This function receives a float argument and returns the integer part of the argument. Truncates a real number to an integer.

Example 1. Trunc()

<HTML>
<!--FUNCTRUNC.dbsp-->
<BODY>

<H1>Trunc() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="TRUNC(5.7)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="TRUNC(-5.7)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="TRUNC(4.34)"/>

The result of the operation : <span style="color : red">TRUNC(5.7)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">TRUNC(-5.7)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">TRUNC(4.34)</span> IS <span style="color:red"><#RESULT3/></span> </BODY>
</HTML>

Test example

 

CEIL(float)

This function receives a float number as argument and returns the next integer number bigger than the argument. Rounds argument up toward positive infinity.

Example 1. Ceil()

<HTML>
<!--FUNCCEIL.dbsp-->
<BODY>

<H1>CEIL() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="CEIL(5.7)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="CEIL(-5.7)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="CEIL(4.34)"/>

The result of the operation : <span style="color : red">CEIL(5.7)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">CEIL(-5.7)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">CEIL(4.34)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

FLOOR(float)

This function receives a float argument and returns the predecessor number of the argument. Rounds argument down toward negative infinity.

Example 1. Floor()

<HTML>
<!--FUNCFLOOR.dbsp-->
<BODY>

<H1>Floor() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="FLOOR(5.7)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="FLOOR(-5.7)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="FLOOR(4.34)"/>

The result of the operation : <span style="color : red">FLOOR(5.7)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">FLOOR(-5.7)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">FLOOR(4.34)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

ROUND(float)

This function receives a float argument and returns the predecessor if decimal part is smaller than .5 otherwise returns the consecutive of the argument. Returns the value of X rounded to the nearest whole number.

Example 1. Round()

<HTML>
<!--FUNCROUND.dbsp-->
<BODY>

<H1>Round() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="Round(5.5)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="Round(-5.6)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="Round(4.4)"/>

The result of the operation : <span style="color : red">ROUND(5.5)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">ROUND(-5.6)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">ROUND(4.4)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

LEN(String)

This function receives a String argument and returns the number of characters of the argument.

Example 1. Len()

<HTML>
<!--FUNCLEN.dbsp-->
<BODY>

<H1>Len() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="Len('Computation')"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="Len('DBSPTech')"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="Len('Easy')"/>

The result of the operation : <span style="color : red">Len('Computation')</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">Len('DBSPTech')</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">Len('Easy')</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

RANDOM(INTEGER or NOTHING)

Generates random numbers within a specified range.
This function has two variants:
1.- When receive an Integer argument then return a X integer inside range 0 < X < Argument .
2.- When receive NOT any argument then return a X float inside range 0 < X < 1 .

Example 1. RANDOM()

<HTML>
<!--FUNCRANDOM.dbsp-->
<BODY>

<H1>Random() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="RANDOM()"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="RANDOM(5)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="RANDOM(32000)"/>

The result of the operation : <span style="color : red">RANDOM()</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">RANDOM(5)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">RANDOM(32000)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

ABS(INTEGER or FLOAT)

Returns an absolute value.
This function has two variants:
1.- When receive an Integer argument then return an integer positive result.
2.- When receive an Float argument then return a Float positive result.

Example 1. ABS()

<HTML>
<!--FUNCABS.dbsp-->
<BODY>

<H1>Abs() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="ABS(-7)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="ABS(-8.4)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="ABS(3.2)"/>

The result of the operation : <span style="color : red">ABS(-7)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">ABS(-8.4)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">ABS(3.2)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

PI()

Returns 3.1415926535897932385.
This function doesn't receive parameters.

Example 1. PI()

<HTML>
<!--FUNCPI.dbsp-->
<BODY>

<H1>PI() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="PI()"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="PI()*3*3"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="180/PI()"/>

The constant &pi; : <span style="color : red">PI()</span> IS <span style="color:red"><#RESULT1/></span><br>
The area of a circle with diameter = 6 u. : <span style="color : red">PI()*3*3</span> IS <span style="color:red"><#RESULT2/> u.</span><br>
A radian measure : <span style="color : red">180/PI()</span> IS <span style="color:red"><#RESULT3/> °</span>
</BODY>
</HTML>

Test example

 

FRAC(float)

Returns the fractional part of a real number.
This function receives a float argument and returns a float (fractional part).

Example 1. FRAC()

<HTML>
<!--FUNCFRAC.dbsp-->
<BODY>

<H1>FRAC() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="FRAC(3.3)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="FRAC(-5.6)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="FRAC(0.9)"/>

The result of the operation : <span style="color : red">FRAC(3.3)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">FRAC(-5.6)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">FRAC(0.9)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

LN(float)

Returns the natural log of a real expression.
This function receives a float argument and returns a float.

Example 1. LN()

<HTML>
<!--FUNCLN.dbsp-->
<BODY>

<H1>LN() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="LN(3.3)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="LN(2.7)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="LN(1)"/>

The result of the operation : <span style="color : red">LN(3.3)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">LN(2.7)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">LN(1)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

LOGN(float , float)

Calculates the log of X for a specified base.
This function receives two parameters, the first parameter contains the basis of the logarithm and the second parameter is the number to calculate the logarithm, this function returns a float.

Example 1. LogN()

<HTML>
<!--FUNCLOGN.dbsp-->
<BODY>

<H1>LOGN() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="LOGN(3,3)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="LOGN(10, 1)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="LOGN(10, 2)"/>

The result of the operation : <span style="color : red">LOGN(3,3)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">LOGN(10,1)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">LOGN(10,2)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

SIN(float)

Returns the sine of the angle in radians.
This function receives a parameter float and returns a float.

Example 1. Sin()

<HTML>
<!--FUNCSIN.dbsp-->
<BODY>

<H1>SIN() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="SIN(PI())"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="SIN((220*PI())/180)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="SIN(0)"/>

The Sine of 180° : <span style="color : red">SIN(PI())</span> IS <span style="color:red"><#RESULT1/></span><br>
The Sine of 220° : <span style="color : red">SIN((220*PI())/180)</span> IS <span style="color:red"><#RESULT2/></span><br>
The Sine of 0° : <span style="color : red">SIN(0)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

COS(float)

Returns the cosine of the angle in radians.
This function receives a parameter float and returns a float.

Example 1. Cos()

<HTML>
<!--FUNCCOS.dbsp-->
<BODY>

<H1>Cos() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="COS(PI())"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="COS((220*PI())/180)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="COS(0)"/>

The Cosine of 180° : <span style="color : red">COS(PI())</span> IS <span style="color:red"><#RESULT1/></span><br>
The Cosine of 220° : <span style="color : red">COS((220*PI())/180)</span> IS <span style="color:red"><#RESULT2/></span><br>
The Cosine of 0° : <span style="color : red">COS(0)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

TAN(float)

Returns the tangent of X.
This function receives a parameter float and returns a float.

Example 1. Tan()

<HTML>
<!--FUNCTAN.dbsp-->
<BODY>

<H1>Tan() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="TAN(PI())"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="TAN((220*PI())/180)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="TAN(0)"/>

The TAN of 180° : <span style="color : red">TAN(PI())</span> IS <span style="color:red"><#RESULT1/></span><br>
The TAN of 220° : <span style="color : red">TAN((220*PI())/180)</span> IS <span style="color:red"><#RESULT2/></span><br>
The TAN of 0° : <span style="color : red">TAN(0)</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

SUBSTR(String, integer, integer)

Returns a substring of a string .
This function receives three parameters, first the String , second initial position of substring and third length of substring (many characters).

Example 1. Tan()

<HTML>
<!--FUNCSUBSTR.dbsp-->
<BODY>

<H1>Substr() example.</H1>

<#SETCOOKIE NAME="RESULT1" EXPRESSION="SUBSTR('INTERNATIONAL',6,8)"/>

<#SETCOOKIE NAME="RESULT2" EXPRESSION="SUBSTR('PRECOGNITIONS',1,3)"/>

<#SETCOOKIE NAME="RESULT3" EXPRESSION="SUBSTR('HAPPINESS',1,4)+'Y'"/>

The result of the operation : <span style="color : red">SUBSTR('INTERNATIONAL',6,8)</span> IS <span style="color:red"><#RESULT1/></span><br>
The result of the operation : <span style="color : red">SUBSTR('PRECOGNITIONS',1,3)</span> IS <span style="color:red"><#RESULT2/></span><br>
The result of the operation : <span style="color : red">SUBSTR('HAPPINESS ',1,4)+'Y'</span> IS <span style="color:red"><#RESULT3/></span>
</BODY>
</HTML>

Test example

 

NOW(String)

Returns the timestamp in a string with different formats.
This function could receives one parameter, the next table describe the parameter options that receives.
Not parameters Return timestamp in complete format.
dd Return current day.
mm Return current month.
yy Return current year.
hh Return current hour.
mi Return current minute.
ss Return current second.
ms Return current millisecond.
dy Return day year, the first day is 1° of January.
dw Return day week, the first day is monday.
wy Return week year, the first week is the first complete week in the year.
dd/mm/yyyy Return date in format day/month/year.
mm/dd/yyyy Return date in format month/day/year.
hm Return time in format hour:minute.
hms Return time in format hour:minute:second.

 

DATEADD(STRING, INTEGER, STRING)

This function allows us to add days, hours, years, etc. To certain date.
This function receives three params.

  • Part: This is a string that indicates what part increment ( or decrement ) the values permited are 'yy', 'mm', 'dd', 'hh', 'mi', 'ss'. For information see function now().
  • Increment: This is an integer that it can be negative if you wish decrement.
  • date: This is an string that represents the date base that will add or to subtract the increment.

Example 1. DATEADD()



Suppose that you capture currente datetimestamp and apply it operations.

Source code
Test example


 

DATEDIFF(STRING, STRING, STRING)

This function allows us to know the difference days, years, etc. between two dates.
This function receives three params.

  • Part: This is a string that indicates what part you wish know the dirfference, the values permited are 'yy', 'mm', 'dd', 'hh', 'mi', 'ss'. For information see function now().
  • date1, date2 : Those are string that represents the dates to be compared.

Example 1. DATEDIFF()



Suppose that you wish to know number of days between today at your birthdate.

Source code
Test example