Column Value Date 0000-00-00 to Blank

Column Value Date 0000-00-00 to Blank

vincmeistervincmeister Posts: 136Questions: 36Answers: 4
edited March 2016 in Free community support

Hello,

How to changes 0000-00-00 from MYSQL to blank in datatables ?
Please advise, thank you

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    You can use the API to enable and disable fields: field().enable() and field().disable().

    You might want to use the event listeners for initEdit and initCreate to decide if you want to call them.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    hi allan,

    sorry i'm editing my previous question because i already found the answer in the manual by using editor.hide and show.
    i think your answer is for my prev question.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Could you just post your new question in future, rather than editing your old one. Now my reply makes no sense for anyone who is searching for the same issue. Thanks.

    Regarding your modified question you would use a get formatter.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4
    edited March 2016

    Thanks and Sorry Allan.

    I already create a get and set formatter, my code :

    Field::inst( 'act_log_incoming.outgoing_date' )
                    ->validator( 'Validate::dateFormat', array(
                    'empty' => true,
                    'format' => 'd-m-Y g:i A'
                    ) )
                    ->getFormatter( 'Format::datetime', array(
                        'from' => 'Y-m-d H:i:s',
                        'to' =>   'd-m-Y g:i A'
                    ) )
                    ->setFormatter( 'Format::datetime', array(
                        'from' => 'd-m-Y g:i A',
                        'to' =>   'Y-m-d H:i:s'
                    ) )
    

    and I want to change the result, if the date on MySQL 0000-00-00 , datatables will show blank, not 30-11--0001 12:00 AM
    my result now is 30-11--0001 12:00 AM

    please advise, thank you

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    You need to use a custom formatter method that will detect the value you want to be blank and return the empty string. The other data would then be formatted as a date, as required.

    The documentation for custom formatters is here.

    Regards,
    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4
    edited March 2016

    thanks Allan, i'm using something like this, and it works

    ->getFormatter( function ( $val, $data, $opts ) {
                        if ($val === "0000-00-00"){
                            echo "";                        
                        }else{
    
                            return date( 'Y-m-d', strtotime( $val ) );
                        }
                    } )
    
This discussion has been closed.