Functions by Topic
The following sections list ColdFusion by topics, meaning that the functions in each section perform related tasks. String-Manipulation FunctionsThe ColdFusion string-manipulation functions can be used to perform operations on character data. Strings can be hard-coded constants, table column values, or ColdFusion fields. As with all ColdFusion functions, these string-manipulation functions can be nested.
Table C.1 contains the available functions for string manipulationrelated processing.
Date and Time FunctionsThe ColdFusion Date and Time functions enable you to perform date and time manipulations on table columns and user-supplied fields.Many of these functions work with date/time objects. A date/time object is a ColdFusion internal representation of a complete date and time. These objects are designed to facilitate the passing of date/time information between various ColdFusion functions and are not designed to be displayed as is. If you need to display a date/time object, you must use one of the date/time formatting functions.NOTE
ColdFusion date/time objects are not the same as ODBC date/time fields. Use the CreateODBCDateTime() function to convert ColdFusion date/time objects to the ODBC format.
Many ColdFusion date and time functions take date and time values as parameters. These parameters must be valid and within a set range; otherwise, a ColdFusion syntax error is generated. The range of values allowed for each date and time field is listed in Table C.2.
Year | 0 | 9999 |
Month | 1 | 12 |
Day | 1 | 31 |
Hour | 0 | 23 |
Minute | 0 | 59 |
Second | 0 | 59 |
NOTE
Year values of less than 100 are treated as 20th-century values, and 1900 is added automatically to them.Several of the ColdFusion date and time functions enable you to work with parts of the complete date/time objectto add days or weeks to a date, or to find out how many weeks apart two dates are, for example. These functions require you to pass a date/time part specifier that is passed as a string. (They must have quotation marks around them.) The complete list of specifiers is explained in Table C.3.Table C.3. ColdFusion Date/Time Specifiers SPECIFIERDESCRIPTIONDDayHHourMMonthNMinuteQQuarterSSecondLMillisecondWWeekday (day of week)WWWeekYDay of yearYYYYYearTable C.4 contains the available functions for date- and time-related processing.Table C.4. Date and Time Functions FUNCTIONDESCRIPTIONCreateDate()Returns a ColdFusion date/time object that can be used with other date-manipulation or formatting functionsCreateDateTime()Returns a ColdFusion date/time object that can be used with other date- and time-manipulation or formatting functionsCreateODBCDate()Returns a date in an ODBC date/time field that can safely be used in SQL statementsCreateODBCDateTime()Returns an ODBC date/time field that can safely be used in SQL statementsCreateODBCTime()Returns a time in an ODBC date/time field that can safely be used in SQL statementsCreateTime()Returns a time in a ColdFusion date/time object that can be used with other time-manipulation or formatting functionsCreateTimeSpan()Creates a date/time object that can be used to rapidly perform date- and time-based calculationsDateAdd()Adds or subtracts values to a date/time objectDateCompare()Compares two dates to determine whether they are the same or whether one is greater than the otherDateConvert()Converts local machine time to UTC (Universal Coordinated Time) time or vice versaDateDiff()Returns the difference between two datesDatePart()Returns the specified part of a passed dateDay()Returns a date/time object''''s day of month as a numeric valueDayOfWeek()Returns a date/time object''''s day of week as a numeric valueDayOfWeekAsString()Returns the English weekday name for a passed day-of-week numberDayOfYear()Returns a date/time object''''s day of year as a numeric valueDaysInMonth()Returns the number of days in a specified monthDaysInYear()Returns the number of days in a specified yearFirstDayOfMonth()Returns the day of year on which a specified month startsGetHTTPTimeString()Formats a ColdFusion date/time object according to the HTTP standard outlined in RFC 1123GetTimeZoneInfo()Returns a structure containing relevant server time zone informationHour()Returns a date/time object''''s hour as a numeric valueIsDate()Checks whether a string contains a valid dateIsLeapYear()Checks whether a specified year is a leap yearIsNumericDate()Checks whether a value passed as a date in the ColdFusion internal date format is in fact a legitimate dateMinute()Returns a date/time object''''s minute as a numeric valueMonth()Returns a date/time object''''s month as a numeric valueMonthAsString()Returns the English month name for a passed month numberNow()Returns a date/time object containing the current date and timeParseDateTime()Converts a date in string form into a ColdFusion date/time objectQuarter()Returns a date/time object''''s quarter as a numeric valueSecond()Returns a date/time object''''s second as a numeric valueWeek()Returns a date/time object''''s week in year as a numeric valueYear()Returns a date/time object''''s year as a numeric value Data Formatting FunctionsPowerful data-manipulation functions and database-interaction capabilities are pretty useless unless you have ways to display data in a clean, readable format. ColdFusion data addresses this need by providing an array of highly capable formatting functions.
Many of these functions take optional format masks as parameters, thereby giving you an even greater level of control over the final output.
Displays text wit263 codes using a preformatte259 block | |
Converts supplied text into a safe format, converting any HTML control characters to their appropriate entity codes | |
NumberFormat() | Displays numeric values in a readable format |
TimeFormat() | Displays the time portion of a date/time object in a readable format |
ParagraphFormat() | Converts text with embedded carriage returns for correc275 display |
YesNoFormat() | Converts trUE and FALSE values to Yes and No |
Mathematical Functions
To assist you in performing calculations, ColdFusion comes with a complete suite of mathematical functions, random number-generation functions, and arithmetic expressions. As with all ColdFusion functions, these mathematical functions can be nested.Some of the mathematical functions take one or more numeric values as parameters. You can pass real values, integer values, and ColdFusion fields to these functions.Table C.6 lists the supported arithmetic expressions.Table C.6. ColdFusion Arithmetic Expressions EXPRESSIONDESCRIPTION+Addition-Subtraction*Multiplication/DivisionMODModular (finds remainder)\Integer division (both values must be integers)^PowerTable C.7 contains the available functions for mathematical processing.Table C.7. Mathematical Functions FUNCTIONDESCRIPTIONAbs()Absolute value of the passed numberAcos()Arccosine of the passed numberAsin()Arcsine of the passed number, in radiansAtn()Arctangent of the passed numberCeiling()The closest integer greater than the passed numberCos()Cosine of the passed numberDecrementValue()Number decremented by 1Exp()E to the power of the passed numberFix()The closest integer smaller than the passed number, if the passed number is greater than or equal to 0. Otherwise, the closest integer greater than the passed numberIncrementValue()Number incremented by 1Int()The closest integer smaller than the passed numberLog()Natural logarithm of the passed numberLog10()Base 10 log of the passed numberMax()The greater of two passed numbersMin()The smaller of two passed numbersPi()Value of pi as 3.14159265359Rand()A random number between 0 and 1Randomize()The random number generator seeded with the passed numberRandRange()A random integer value between two passed numbersRound()The integer closest (either greater or smaller) to the passed numberSgn()Signeither 1, 0, or 1, depending on whether the passed number is negative, 0, or positiveSin()Sine of the passed numberSqr()Square root of the passed numberTan()Tangent of the passed number International FunctionsColdFusion fully supports the display, formatting, and manipulation of international dates, times, numbers, and currencies. To use ColdFusion''''s international support, you must specify the locale. A locale is an encapsulation of the set of attributes that govern the display and formatting of international date, time, number, and currency values. The complete list of supported locales is shown in Table C.8.
NOTE
Note that because ColdFusion is now a Java-based application, you must use Java standard locales, as opposed to the locales supported by ColdFusion 5.You will find information on standard locales here: http://www.inter-locale.com/index.jsp You must use the SetLocale() function to set the locale. You can retrieve the name of the locale currently in use with the GetLocale() function.To use ColdFusion''''s international support, you must use the LS functions listed later in this section. These functions behave much like the standard date, time, and formatting functions, but they honor the current locale setting.NOTEThe ColdFusion server variable SERVER.ColdFusion.SupportedLocales contains a comma-delimited list of the supported locales.
Table C.9 contains the available functions for international-related processing.
CharsetDecode() | Converts a string to a binary object, based on a character set for encoding |
CharsetEncode() | Converts a binary object to a string, based on a specified character set for encoding |
GetLocale() | Returns the name of the locale currently in use |
LSCurrencyFormat() | Displays currency information formatted for the current locale |
LSDateFormat() | Displays the date portion of a date/time object in a readable format |
LSEuroCurrencyFormat() | Displays euro currency formatted correctly |
LSIsCurrency() | Checks whether a string contains a valid currency for the current locale |
LSIsDate() | Checks whether a string contains a valid date for the current locale |
LSIsNumeric() | Checks whether a specified value is numeric, taking into account the current locale |
LSNumberFormat() | Displays numeric values in a locale-specific, readable format |
LSParseCurrency() | Converts a locale-specific number in string form into a valid number |
LSParseDateTime() | Converts a locale-specific date in string form into a ColdFusion date/time object |
LSParseEuroCurrency() | Converts a currency string containing the euro symbol or sign to a number |
LSParseNumber() | Converts a locale-specific number in string form into a valid number |
LSTimeFormat() | Displays the time portion of a date/time object in a locale-specific, readable format |
SetLocale() | Sets the name of the locale to be used by any subsequent calls to the LS functions |
List-Manipulation Functions
ColdFusion lists are an efficient way to manage groups of information. Lists are made up of elements, which are values separated by delimiting characters. The default delimiter is a comma, but you can change this to any character or string, as required. Lists are actually simple two-dimensional arrays. For more complex or multidimensional lists, use arrays instead.This list format is well suited for ColdFusion applications. It is both the format tha275 forms use to submit fields with multiple values and the format used by SQL to specify lists in SQL statements.When using the list-manipulation functions, remember the following:List-manipulation functions that add to, delete from, or change a list do not alter the original list passed to them. Rather, they return an altered list to you for manipulation. If you need to update the passed list itself, you must use <cfset> to replace the list with the newly modified list.All list functions accept as an optional last parameter a string with delimiters to be used in the processing of the list. If this parameter is omitted, the default comma delimiter is used.The number 1 is always the starting position in any list. When referencing list functions, remember that lists always start at position 1, never 0.When evaluating a list, be aware that ColdFusion will ignore any empty items in a list. If you have a list defined as "Laura, John, Sean, , ,Bryan", it will be evaluated as a four-element list, not a six-element list.NOTEAll the ColdFusion list-manipulation functions have names that begin with the word list, making them easy to spot in your code.
TIP
Lists can be used in conjunction with the <cfloop> tag for processing.Table C.10 contains the available functions for list manipulationrelated processing.Table C.10. List-Manipulation Functions FUNCTIONDESCRIPTIONListAppend()Adds an element to the end of a listListChangeDelims()Changes a list''''s delimitersListContains()Performs a case-sensitive list search for an element containing specified textListContainsNoCase()Performs a case-insensitive list search for an element containing specified textListDeleteAt()Deletes an element from a listListFind()Performs a case-sensitive list search for a specific elementListFindNoCase()Performs a case-insensitive list search for a specific elementListFirst()Returns the first element in a listListGetAt()Gets a specific list element by indexListInsertAt()Inserts an element into a listListLast()Returns the last element in a listListLen()Returns the number of elements in a listListPrepend()Inserts an element at the beginning of a listListSort()Sorts a listListQualify()Returns the contents of a specified list with qualifying characters around each list elementListRest()Returns a list containing all the elements after the first elementListSetAt()Sets a specific list element by indexListValueCount()Performs a case-sensitive search and returns the number of matching elements in a listListValueCountNoCase()Performs a case-insensitive search and returns the number of matching elements in a list Array-Manipulation FunctionsArrays are special variables made up of collections of data. Array elements are accessed via their indexes into the array; to access the third element of a simple array, for example, you would refer to array[3].
ColdFusion supports arrays that use between one and three dimensions. A one-dimensional array is similar to a list, whereas a two-dimensional array is similar to a grid. (Under the hood, ColdFusion queries are essentially two-dimensional arrays.) Three-dimensional arrays are more like cubes.
Arrays are created using the ArrayNew() function. To create an array, you must specify the number of dimensions needed, from one to three. You don''''t need to specify how many elements will be stored in the array; ColdFusion automatically expands the array as necessary.
NOTE
Array elements can be added in any order. If you add an element 10 to an array that has only 5 elements, ColdFusion automatically creates elements 69 for you.Table C.11 contains the available functions for array manipulationrelated processing.Table C.11. Array-Manipulation Functions FUNCTIONDESCRIPTIONArrayAppend()Appends an element to an arrayArrayAvg()Returns the average numeric value in an arrayArrayClear()Deletes all data from an arrayArrayDeleteAt()Deletes a specific array elementArrayInsertAt()Inserts an element into an arrayArrayIsEmpty()Checks whether an array has any dataArrayLen()Returns the length of an arrayArrayMax()Returns the greatest numeric value in an arrayArrayMin()Returns the lowest numeric value in an arrayArrayNew()Creates a new arrayArrayPrepend()Inserts an element at the beginning of an arrayArrayResize()Resizes an arrayArraySet()Sets a specific array elementArraySort()Sorts an arrayArraySum()Returns the sum of numeric values in an arrayArraySwap()Swaps the values in two array elementsArrayToList()Converts a one-dimensional array to a listIsArray()Checks whether a variable is a valid ColdFusion arrayListToArray()Converts a list to a one-dimensional array Structure-Manipulation FunctionsColdFusion structures are special data types that contain one or more other variables. Structures are a way to group related variables together.
Table C.12 contains the available functions for structure manipulationrelated processing.
Query-Manipulation Functions
ColdFusion uses queries to return sets of data. Most queries are created with the <cfquery> tag, but other tags (<cfpop> and <cfldap>) also return data in queries. Additionally, ColdFusion enables you to programmatically create your own queries using the QueryNew function and set query values using QuerySetCell.NOTEColdFusion queries are essentially arrays with named columns. You therefore can use any of the array functions with queries.
Table C.13 contains the available functions for query manipulationrelated processing.
IsQuery() | Checks whether a variable is a valid ColdFusion query |
QueryAddColumn() | Adds a new column to a specified query |
QueryAddRow() | Adds a row to an existing ColdFusion query |
QueryNew() | Returns a new query object, optionally with specified columns |
QuerySetCell() | Sets the values of specific cells in a query |
Security Functions
ColdFusion supports advanced security contexts that let you create complete security systems to secure your applications. Security is managed and maintained using the ColdFusion Administrator. After security is established, you can make a call to the <Cfauthenticate> tag to return security information. Use these security functions to interact with that security information.Table C.14 contains the available functions for security-related processing.Table C.14. Security Functions FUNCTIONDESCRIPTIONAuthenticatedContext()Deprecated (no longer in use)AuthenticatedUser()Deprecated (no longer in use)GetAuthUser()Returns the ID of the user currently logged in to the ColdFusion security frameworkIsAuthenticated()Deprecated (no longer in use)IsAuthorized()Deprecated (no longer in use)IsProtected()Deprecated (no longer in use)IsUserInRole()Checks to see if current user (logged in to the ColdFusion security framework) is in the specified role. Returns TRue or False System FunctionsThe ColdFusion system functions let you manipulate file paths, create temporary files, and verify file existence.
Table C.15 contains the available functions for system-related processing.
DirectoryExists() | Checks for the existence of a specified directory |
ExpandPath() | Converts a relative or absolute path into a fully qualified path |
FileExists() | Checks for the existence of a specified file |
GetCurrentTemlatePath() | Returns the complete path of the template calling this function |
GetdirectoryFromPath() | Extracts the drive and directory (with a trailing backslash) from a fully specified path |
GetFileFromPath() | Extracts the filename from a fully specified path |
GetMetaData() | Gets metadata from an object that supports introspection |
GetMetricData() | Deprecated (no longer in use) |
GetProfileString() | Gets the value of a profile entry in an .ini-format initialization file |
GetTempDirectory() | Returns the full path of the operating system temporary directory |
GetTempFile() | Creates and returns the full path to a temporary file for use by your application |
GetTemplatePath() | Deprecated (no longer in use) |
SetProfileString() | Sets the value of a profile entry in an .ini-format initialization file |
Client VariableManipulation Functions
Client variables enable you to store client information so it is available between sessions. Client variables can be accessed just like any other ColdFusion variables; standard variable access tools, such as <cfset>, can therefore be used to set variables. In addition, these functions provide special variable-manipulation capabilities.Table C.16 contains the available functions for client variable manipulationrelated processing.Table C.16. Client VariableManipulation Functions FUNCTIONDESCRIPTIONDeleteClientVariable()Deletes specified client variablesGetClientVariablesList()Returns a comma-delimited list of the read/write client variables available for use Expression Evaluation FunctionsColdFusion enables you to perform dynamic expression evaluation. This is an advanced technique that allows you to build and evaluate expressions on the fly.
Dynamic expression evaluations are performed on string expressions. A string expression is just thata string that contains an expression. The string "1+2" contains an expression that, when evaluated, returns 3. String expressions can be as simple or as complex as necessary.
Table C.17 contains the available functions for expression evaluationrelated processing.
DE() | Flags an expression for delayed evaluation |
Evaluate() | Evaluates string expressions |
IIf() | Performs an inline if statement |
SetVariable() | Sets a specified variable to a passed value |
Bit- and Set-Manipulation Functions
ColdFusion provides a complete set of bit-manipulation functions for use by advanced developers only. These functions enable you to manipulate the individual bits within a 32-bit integer.NOTEAny start, length, or position parameters passed to the bit-manipulation functions must be in the range of 031.
Table C.18 contains the available functions for bit- and set-manipulationrelated processing.
BitAnd(x, y) | Returns x and y |
BitMaskClear (x, start, length) | Returns x with bits of length cleared, beginning at the starting position |
BitMaskRead (x, start, length) | The value of x with bits of length length, beginning at the starting position |
BitMaskSet (x, mask, start, length) | Returns x with mask occupying the length bits beginning at the starting position |
BitNot(x) | Returns not x |
BitOr(x, y) | Returns x | y |
BitSHLN(x, n) | Returns x << n |
BitSHRN(x, n) | Returns x >> n |
BitXor(x, y) | Returns x^y |
Conversion Functions
These functions are provided to enable you to easily convert data from one type to another. This list is not all inclusive; some data-conversion functions are listed elsewhere throughout this appendix.Table C.19 contains the available functions for conversion-related processing.Table C.19. Conversion Functions FUNCTIONDESCRIPTIONJavaCast()Casts a variable for use within a Java objectJSStringFormat()Formats a specified string so that it is safe to use with JavaScripttoString()Converts any value, including binary values, into a stringtoScript()Converts a ColdFusion variable to a Java Script or Action Script variable. XML FunctionsThe following functions were introduced in ColdFusion MX and enable you to work with Extended Markup Language (XML) documents and ColdFusion XML objects. Table C.20 lists the functions that can be used to process XML. Also note that ToString() can be used on an XML document object.
IsXML() | Returns TRue or False indicating whether or not the string passed to it is valid XML |
IsXMLAttribute() | Returns true or False indicating whether or not the object passed to it is an attribute node form an XML DOM |
IsXMLDoc() | Returns true or False indicating whether the parameter is a valid XML document object |
IsXMLElem() | Returns TRue or False indicating whether the parameter is an XML document object element |
XMLGetNodeType() | Indicates the type of node being passed as a parameter (e.g., element node as opposed to an attribute note) |
IsXMLNode() | Returns True or False indicating whether or not the parameter is a node from an XML DOM |
IsXMLRoot() | Returns true or False indicating whether the function argument is the root element of an XML document object |
XMLChildPos() | Returns the position of a child in an array of XML children |
XMLElemNew() | Returns the XML document object (first parameter) with a new element (specified in the second parameter) |
XMLFormat() | Returns a string formatted in which special XML characters are escaped |
XMLNew() | Creates an XML document object |
XMLParse() | Searches through a string of XML for a document tree object and returns that object |
XMLSearch() | Returns an array of XML object nodes after searching for an XPath through an XML document string |
XMLTransform() | Applies an XML style sheet (XSLT) to an XML document string and returns the XSL-formatted string |
XMLValidate() | Validates XML files or documents against specified Schema or DTD |
Event Gateway Functions
The functions listed in table C.21 relate to the use of ColdFusion''''s Event Gateway feature.Table C.21. Event Gateway Functions FUNCTIONDESCRIPTIONGetGatewayHelper()Retrieves a Java "Gateway Helper" object for use with a ColdFusion event gatewaySendGatewayMessage()Sends a message through the specified event gateway SOAP FunctionsThe functions listed in table C.22 are useful when working with Simple Open Access Protocol data, as you do with Web Services.
AddSOAPRequestHeader() | Adds a SOAP header to a request you''''re sending to a Web Service |
AddSOAPResponseHeader() | Adds a SOAP response header from your Web Service |
GetSOAPRequest() | Returns an XML object containing a SOAP request |
GetSOAPRequestHeader() | Retrieves a SOAP request header from a message |
GetSOAPResponse() | Returns an XML object containing a SOAP response |
GetSOAPResponseHeader() | Retrieves a SOAP response header from a message |
IsSOAPRequest() | Indicates whether or not a CFC is being called as a Web Service |