Programming instructions
Understanding CFML elements 19
If you did not include the pound signs around the DateFormat(Now(), "mm/ddyyy")
function, the output for the previous example would display as follows:
For more information about how to use pound signs with functions, see Developing
ColdFusion MX Applications with CFML.
Variables
Variables let you store data in memory on the server. Variables always have a name and a
value. You can assign a value to a variable, or you can instruct ColdFusion to assign
variable values based on data that it retrieves from a data source, such as a database table.
Naming variables
You must use the following rules for naming ColdFusion variables:
• Names are case insensitive (uppercase, lowercase, or mixed case).
• Names can contain only letters, numbers, and underscore characters.
• Each name must begin with a letter.
• Special characters (such as double quotation marks ("), reserved names (such as
functions and tags), and spaces are not allowed.
Ways to use variables
You can use a variable for the following purposes:
• Store data collected from a form.
• Store results of a calculation (such as the number of database records returned).
• Use as input to a function.
Creating variables with the cfset tag
ColdFusion lets you create variables as you need them. You create the variable (name and
value) using the
cfset tag. The syntax for this tag is:
<cfset variable_name = value>
In the following examples, the variables are assigned a string literal value. All string literal
values are surrounded by double quotation marks.
<cfset my_first_name = "Kaleigh">
<cfset my_last_name = "Smith">