DataTables > Date Format

DataTables > Date Format

qqashishqqashish Posts: 34Questions: 10Answers: 0
edited May 2020 in Free community support

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

I am using Datatables( Not Editor ) with server side. In serverside php script.

array(
'db' => 'start_date',
'dt' => 4,
'formatter' => function( $d, $row ) {
return date( 'jS M y', strtotime($d));
}

I want blank dates like 0000 00 00 in mysql to be shown here as blank, however its showing as 30th Nov -1.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406
    edited May 2020 Answer ✓

    The formatter is a function. You can check $d for '0000 00 00' with a simple if statement and then return '' from that function.

    'formatter' => function( $d, $row ) {
        if ( $d <= '0000 00 00' || $d <= '0000-00-00' ) { //whatever is really returned from db
           return '';
        }
        return date( 'jS M y', strtotime($d));
    }
    
  • qqashishqqashish Posts: 34Questions: 10Answers: 0

    Thanks a lot ! Quick Easy and Working.

This discussion has been closed.