270 likes | 382 Vues
This guide provides an overview of string, date-time, and Boolean variables in ColdFusion. Learn how to create and manipulate string variables using the CFSET tag, and understand how to concatenate strings and display them with CFOUTPUT. Explore the capabilities of date-time variables, including creation with CreateDateTime, and formatting with DateFormat and TimeFormat functions. Additionally, delve into the use of Boolean variables, representing true/false states. This comprehensive resource is essential for developing dynamic ColdFusion applications.
E N D
ColdFusion Basics (Cont’d) 321483 02-14-2002
String, Date-time and Boolean Variables • In addition to numeric variables, ColdFusion can use string, date-time, and Boolean type variables • ColdFusion provides a number of useful string, date-time, and Boolean functions
String Variables • Strings: • Strings are groupings of text • String Variables: • String variables allow you to store text data • String variables follow the same naming conventions of numeric variables
String Variables and <CFSET> • You can assign a string variable a value using the CFSET tag • Example: <CFSET City=“Clarkson University"> “Clarkson University” is also called a string literal
String Variables and <CFSET> • If you want to include a quotation mark in a string you must type two together • Example: <CFSET Name="William ""Buck"" Rogers"> stores William "Buck" Rogers in Name
String variables and <CFOUTPUT> • String variables can be displayed just like numeric variables – using the CFOUTPUT tag and # • ColdFusion substitutes values of variables and functions enclosed in pound signs (#) in string literals • Quotation marks used in the CFSET tag are NOT displayed • They are delimiters for string literals and NOT part of the actual text
Using String Expressions • ColdFusion allows you to form string expressions by using string variables and a string operator • The most useful operator is concatenate (&) which connects one string to another • Example 1:<CFSET FirstName=“Koffi "><CFSET LastName=“N'Da"><CFSET FullName = FirstName & LastName> This stores the string “Koffi N’Da" in the FullName variable
Using String Expressions • Example 2: <CFSET PricePhrase="The price is #DollarFormat(Price)#"> store the phrase "The price is $1,300.00" in string variable PricePhrase, assuming numeric variable Price is 1300.00
Using String Expressions • Unlike other programming languages ColdFusion lets you create string literals that span multiple lines • Example: "Pet" is a valid string literal, the carriage returns are stored after each letter
String Functions Click here to have detailed information on string functions
Date-Time Values and Variables • You can also create variables in ColdFusion that store date and time values • Date and times can range from 100 A.D to 9999 A.D. • For more details on date-time functions: http://nongmon.compsci.buu.ac.th/cfdocs/CFML_Reference/
Creating a date-time Variable • You need to use the CreateDateTime function to create a new date-time variable • Click the link below for more information on the CreateDateTime function
Creating a date-time Variable • Example <CFSET LastUpdate = CreateDateTime(2003,5,19,14,15,50)> Assigns the date 5/19/2003 and time 14:15:50 to the date-time variable LastUpdate
Formatting a Date-time Variable • DateFormat Function • You can use the DateFormat and TimeFormat functions to change the way a date/time is displayed • Takes two parameters, a date-time value and a mask • The mask contains letters that signify different kinds of formatting • Click links below for syntaxes: • DateFormat syntax • TimeFormat syntax
Using DateFormat and TimeFormat • Examples • <CFOUTPUT>#DateFormat(LastUpdate,"mmmm d, yyyy")#</CFOUTPUT>Displays: May 1, 2003 • <CFOUTPUT>#TimeFormat(LastUpdate,"hh:mm:sstt")#</CFOUTPUT>Displays: 02:15:50PM
Date-Time Operations Click here to have detailed information on date-time functions
Boolean Variables • Boolean Data • Represents a status or a situation, such as True or False • Boolean Variables • A Boolean variable can store only two possible values : • True (Yes or On) • False (No or Off) • You can use Boolean variables where a program must take an action depending on a condition
Boolean Functions Click here to have detailed information on Boolean functions
Typeless Expression Evaluation • Unlike traditional programming languages ColdFusion can evaluate an expression even if operands and operators are of different types • Arguments are converted into required data types, as long as the data is reasonable