Examples of Formatting Data

Example 1: This statement applies a format to a date (4/1/1999) value and returns file name as apr-01-1999.txt

Today( sys_date )
Format( sys_date, "mmm-dd-yyyy\\.\\t\\x\\t", file_name )

The same result can be received using macro-variables

Set( file_name, @T"mmm-dd-yyyy\\.\\t\\x\\t" )

 

Example 2: This example applies a format to the value in order_date and sets date_as_string to 6-11-99:

Set( order_date, 1999-06-11 )
Format( order_date, "m-d-yy", date_as_string )

 

Example 3: This statement applies a format to a DateTime value and returns Jan 31, 1999 6 hrs and 8 min:

Format( "1999-01-31 06:08:00", "mmm dd, yyyy h \"hrs and\" m \"min\"', result)

 

Example 4: This example builds a DateTime value from the system date and time using the Today and Now statements. The Format statements applies formatting and returns the system date and time as a text, for example, 6-11-99 8:06 pm:

Today( sys_date )
Now( sys_time )
DateTime( sys_date, sys_time, sys_datetime )
Format(sys_datetime, "m-d-yy h:mm am/pm'")

 

Example 5: This statement applies a format to a numeric value and returns $5.00:

Format( 5, "$#,##0.00", price)

 

Example 6: These statements set result to 0123:

Dim( nbr, number, 123 )
Format( nbr, "0000", result)

 

Example 7: These statements set result to 1,234,567:

Dim( nbr, number, 1234567 )
Format( nbr, "#,###", result)

 

Example 8: These statements set result to (123.00):

Dim( nbr, number, -123 )
Format( nbr, "0.00;(0.00);0", result )

 

Example 9: This statement formats string data and returns A-B-C. The format assigns a character in the source string to each @ and inserts other characters in the format at the appropriate positions:

Format( "ABC", "@-@-@", result )

 

Example 10: This statement returns A*B:

Format( "ABC", "@*@", result )

 

Example 11: This statement returns ABC:

Format( "ABC", "@@@", result )

 

Example 12: This statement returns a space:

Format( "ABC", " ", result )