setFormatter to Current DateTime

setFormatter to Current DateTime

greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

I would like to set a current datetime into the MySQL DB. I don't want to use the update CURRENT_TIME option though on update. I do not have this my_date field in the interface.

I have tried this, but nothing happens in the DB or the interface:

    Editor::inst( $db, 'my_tb' ,'my_id')
        ->fields(
            Field::inst( 'my_id' )->set(false),
                Field::inst( 'my_date' )->setFormatter(  function (  ) { return date('Y-m-d H:i:s'); }  ),

What am I missing please?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

    thanks Colin, this did the trick

    Field::inst( 'signin_visitor_signout_date' )->setValue( function ( ) { return date('Y-m-d H:i:s'); } ),

This discussion has been closed.