ToChar Function
The ToChar function in Expression Builder converts a specified date or numeric expression to a formatted string.
Syntax
ToChar(expression, format)
Result Type
String
Arguments
The following table describes the arguments for the function.
Argument
|
Description
|
expression
|
An expression or field that returns a date, date and time, or a numeric value.
|
format
|
A string that represents the date or number format.
|
The following table describes the date formats for the function.
Format Code
|
Description
|
DD
|
Two-digit day of month (01-31).
|
MM
|
Two-digit month number (01-12 where 01 is JAN).
|
Y
|
Last digit of the year.
|
YY
|
Last two digits of the year.
|
YYYY
|
Four-digit year.
|
HH
|
Hour of day. HH maintains the hour format in 12- or 24-hour format as set in the expression.
|
mm
|
Minutes.
|
ss
|
Seconds.
|
The following table describes the number formats for the function.
Format Code
|
Example
|
Description
|
#
|
####
|
Returns the value with the specified number of digits, with a leading minus sign if the value is negative.
|
0
|
####.00
|
Returns leading zeros. Returns trailing zeros.
|
$
|
$###.00
|
Returns the value with a leading dollar sign.
|
,
|
#,###
|
Returns a comma in the specified position. A comma cannot appear to the right of the decimal point. The format model must not begin with a comma.
|
.
|
###.##
|
Returns a decimal point in the specified position. Only one decimal point is allowed in the format parameter. If the number of digits specified after the decimal point is less than the number of digits available after the decimal point, the decimal will be rounded up.
|
Examples
The following example returns the value 10:
ToChar (10, '##.##')
The following example returns the value 10:
ToChar (10, '##.00')
The following example returns the value 10.24:
ToChar (10.2388, '##.00')
The following example returns the value -10.24
ToChar (-10.2388, '##.##')
The following example converts the value returned by the Timestamp() function into DD/MM/YYYY format:
ToChar(Timestamp(),'DD/MM/YYYY')
For example, if the Timestamp() function returns a value of 02/29/2008 10:58:37, the previous expression evaluates to 29/02/2008.
Related Information
See the following topics for related Expression Builder information:
|