Monday, January 9, 2012

ToText Function

Uses

The ToText function can be used to convert number, date, boolean, or time values to a string (text). It provides you with controls that let you control how the resulting string looks.
It’s mostly used for concatenation (for example, you can create a title for your report that shows the records covered, or a group name that shows the date range included.)
  • Add parameters to a Report title
  • Control how group names appear (you can force your dates to appear in the format 3/7/10 or 20100901.

ToText for Boolean Values

Syntax
ToText(x)

Examples

ExampleResult
ToText({Completed})True when the field Completed is true.
False when the field Completed is false.

ToText for Numbers (and Currency)

SyntaxVariableOptional
ToText(x, y, z, w)xThe number to convert to text
yThe number of decimal places to include in result (optional). The value will be rounded to that decimal place.
zThe character to use as the thousands separator. If you don’t specify one, it will use your application default. (Optional.)
wThe character to use as the decimal separator. If you don’t specify one, it will use your application default. (Optional.)

Examples

ExampleResult
ToText(12345.678)“12345.678″
ToText(12345.678,2)“12345.67″
ToText(12345.678,0)“12345″
ToText(12345.678, 0, ‘,’, ‘.’)“12,345.67″
ToText(12345.678,0,”")“12345″
“Time Logged for Change # ” & ToText(12345.567,0,”")
“Time Logged for Change # 12345″

ToText for Dates

SyntaxVariableOptional
ToText(x, y)xThe date value to be converted.
yA text string that defines how the value is to be formatted. (Optional)

Examples (where datefield = January 15, 2011)

ExampleResult
ToText({datefield}, “yyyyMM”)“201101″
ToText({datefield},”dd-MMM-yyyy”)“15-Jan-2011″
ToText({datefield},”dd MMM yyyy”)“15 Jan 2011″
ToText({datefield},”MM/dd/yy”)“01/15/11″
ToText({datefield},”dddd, MMM d, yyyy”)“Saturday, Jan 1, 2011″
This looks a little confusing at first. Sometimes d’s return the day of the week and sometimes they return a number. This is because the format is determined by the specific pattern:
PatternResult
dNumeric day of month without leading zero (1, 7, 31)
ddNumeric day of month with leading zero (01, 07, 31)
dddThree day abbreviation of day of week (Mon, Sat)
ddddFull name of day of week (Monday, Saturday)
MNumeric month without leading zero (1, 7, 12)
MMNumeric month with leading zero (01, 07, 12)
MMMThree letter abbreviation of month (Jan, Feb, Mar)
MMMMFull name of month (January, February, March)
yyLast two digits of year (11, 14, 22)
yyyyFull four digits of year (2011, 2014, 2022)

ToText for Times

SyntaxVariableOptional
ToText(x, y, z, w)xThe time value to be converted.
yA text string that defines how the value is to be formatted. (Optional)
zA text string defining the AM string. (Optional)
wA text string defining the PM string. (Optional)

Examples (where timefield =2:43:23 p.m.)

ExampleResult
ToText({timefield}, “HH:mm:ss”)“14:43:23″
ToText({timefield}, “hh:mm:ss tt”)“02:43:23 PM”
ToText({timefield},”h*mm*ss tt”,’am’, ‘pm’)“2*43*23 pm”
Here are the patterns used by ToText when converting time:
PatternResult
hHours without leading zeros in 12 hour format (1, 7, 12)
hhHours with leading zeros in 12 hour format (01, 07, 12)
HHours without leading zeros in 24 hour format (1, 12, 17, 24)
HHHours with leading zeros in 24 hour format (01, 12, 17, 24)
mMinutes without leading zeros (5, 15, 55)
mmMinutes with leading zeros (05, 15, 55)
sSeconds without leading zeros (5, 15, 55)
ssSeconds with leading zeros (05, 15, 55)
t, ttIncludes a single or multi-character AM/PM string.
If you want to include any of the pattern characters in your resulting string, you can. You just need to enclose them in quotes.
ExampleResult
ToText({timefield}, “hh ‘h’ mm ‘min’ ss ‘sec’”)“02 h 43 min 23 sec”

No comments:

Post a Comment