![]() ![]() ![]() |
When dates are returned by ColdFusion, they might not be in precisely the format in which you want it displayed. ColdFusion provides special formatting functions that allow you to format dates for output.
The following functions are available for manipulating dates, times, and numbers:
Date, Time, and Number Formatting Functions | |
---|---|
Function |
Description |
DateFormat(Date[,mask]) |
Case-insensitive. Creates a custom-formatted U.S. English date value. Use LSDateFormat for international date formats. |
TimeFormat(Date[,mask]) |
Case-sensitive. Create a custom-formatted time value. |
NumberFormat(Number[,mask]) |
Create a custom-formatted number value. |
Brackets indicate optional arguments.
If the mask has no sign specifier, positive and negative numbers will not align in columns. Thus, if you expect to have both positive and negative numbers, either use the ( ) or use the "-" sign, which will force a space in front of positive numbers and a minus in front of negative numbers.
To achieve the correct column spacing on the output, use the <PRE>
tag.
The functions listed in the following table provide special formatting options.
Formatting Functions | |
---|---|
Function |
Description |
HTMLCodeFormat |
Useful for display of HTML code posted using TEXTAREA fields. Strips carriage returns and escapes all special characters (<, >, ", &). |
HTMLEditFormat |
Behaves identically to HTMLCodeFormat except that it does not add the <PRE> tag to the output text. |
ParagraphFormat |
Useful for displaying data entered into TEXTAREA fields. Converts CR/LF sequences into spaces and double CR/LF sequences into HTML paragraph markers (<P>). |
PreserveSingleQuotes |
Useful in SQL statements to prevent ColdFusion from automatically escaping single quotes contained in values derived from dynamic parameters. For example, to include a dynamic parameter in a SQL statement and suppress the escaping of single quotes, use the syntax:SELECT * FROM Customers |
StripCR |
Useful for preformatted (PRE) display of data entered into TEXTAREA fields. Strips all carriage returns from the field. |
URLEncodedFormat |
URL encodes the string parameter that is passed to it (replaces spaces with a "+" and non-alphanumeric characters with equivalent hexadecimal escape sequences). This function enables you to pass arbitrary strings (including those with spaces in them) within URLs. (ColdFusion automatically decodes all URL parameters that are passed to an application page.) |
ValueList & QuotedValueList |
The two output functions ValueList and QuotedValueList facilitate using the results of queries to drive subsequent queries. The ValueList function takes as its argument the name of a query column, such as Customers.CustomerID, and returns a comma-separated list of the values for each of the records in the query for that column. For example, if you run a query that returns four distinct customer records, the result of ValueList function would be like: 22,43,51,96. The QuotedValueList function would return '21,' '43,' '51,' '96' for the same data. |
YesNoFormat |
Displays Boolean data as Yes or No. All non-zero values display as Yes. Zero values display as No. |
The next section covers the presentation of data with the CFOUTPUT tag.
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.