date Format in table

Skip to first unread message

Everson Nino

Jan 8, 2021, 5:42:39 PM1/8/21
to ZnetDK

I'm not able to display date field in Brazilian format  (dd/mm/YYYY) in the table.

In the form displays correct .

In locale_pt.php is set
define ('LC_LOCALE_ALL', serialize(array('pt_BR','pt'))); 

Pascal Martinez

Jan 11, 2021, 5:45:27 AM1/11/21
to ZnetDK
Hi Nino,

To format a date displayed in a datatable, you have 2 options :
  1. Option 1 : if your date value is stored in a SQL table, you can specify the column's name to format as locale date by initializing the  \DAO::$dateColumns property into the  \DAO::initDaoProperties(). Here is an example of a DAO class (located within the applications/default/app/model/ folder) :
    namespace app\model;
    class MyDAO extends \DAO {
        protected function initDaoProperties() {
            $this->table = "my_table";
    $this->dateColumns = ['my_date_column'];
  2. Option 2 : when fetching the rows to display in the datatable, call the \Convert::toLocaleDate() method to convert an ISO Date to a locale date according your locale settings. Here is an example of controller's action with date conversion :
    static protected function action_tabledata() {
        $myDAO = new \app\model\MyDAO();
        $tableData = array();
        while($row = $myDAO->getResult()) {
            // Extra column 'my_date_column_locale' (localized date)
            $row['my_date_column_locale'] = \Convert::toLocaleDate($row['my_date_column']);
            $tableData[] = $row;
        /* Response to AJAX request */
        $response = new \Response();
        $response->rows = $tableData;
        $response->success = true;
        return $response;
In addition, you can force a specific date format by defining into your locale_pt.php script the following PHP constant :
define('LC_LOCALE_DATE_FORMAT', '%d-%m-%y');  

Hoping it will be helpful.

ZnetDK Developer

Everson Nino

Jan 11, 2021, 10:27:12 AM1/11/21
to ZnetDK
Unfortunately I was not successful with the suggestions sent. 

After many attempts, I arrived at the result through the code. 

while($row = $engdesenhosDAO->getResult()) {
if( $row['data'] != "" ){
$dt = date_create($row['data']);
$row['data'] = date_format($dt, 'd/m/Y');
                $desenhosFound[] = $row;

Dear Pascal, thank you so much for your return. I am very satisfied with the znetdk Platform. 

God bless you all. 

Pascal Martinez

Jan 11, 2021, 3:33:21 PM1/11/21
to ZnetDK
Thank you for your feedback and your contribution.
Reply all
Reply to author
0 new messages