The data is stored in a raw format in the database. For example, the Date type data is stored as yyyy-mm-dd. For pages like List, View, Print, you can customize data appearance by defining the View as settings in Page Designer.
Using the formatted data in events. ViewControl::Format function
If there is a need to use formatted data in events, for example, when sending emails to users, you can use the ViewControl::Format function.
Syntax
ViewControl::Format($data, $FieldName, $TableName);
Arguments
$data
raw data to be formatted.
$FieldName
the field that contains the data to be formatted.
$TableName
the name of the current table
Example 1
Using the ViewControl::Format function in the AfterAdd event:
echo $values['Date Listed'] ."<br>";
echo ViewControl::Format($values, 'Date Listed', 'Cars' );
The first line of the code sample displays raw data (e.g., 2014-10-15), the second one - the formatted data (US date format, e.g., 10/15/2014).
Example 2
If you need to use this function in button's server code (where you do not have access to $values array) this is what you can do. This will work with the button added to View/Edit pages or with the button button inserted into the grid:
$data = $button->getCurrentRecord();
$dateListed = ViewControl::Format($data, 'Date Listed', 'Cars');
This function can also be used for a Lookup wizard field. In this case, raw data is stored in the Link field, and the ViewControl::Format function displays the values of the Display field.
See also:
•Button object: getCurrentRecord()
•"Edit as" settings: Lookup wizard