Set date only on insert

Set date only on insert

alf007alf007 Posts: 37Questions: 15Answers: 0
edited March 2016 in Free community support

How can I set the date only on insert?

Here is part of my code:

Field::inst( 'modelos.create_date' )
    ->getFormatter( function ( $val, $data, $opts ) {
        return date( 'd-m-Y', strtotime( $val ) );
    } )
    ->setValue( date("Y-m-d") ),

The problem is that, when ever I update the row I update also the date. As you see I get the date when I add the record but I will like to set the date only when I add not when I update.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,785Questions: 1Answers: 10,511 Site admin
    Answer ✓

    This is a perfect use case for server-side events. Listen for the preEdit event and set the value there.

    Allan

  • alf007alf007 Posts: 37Questions: 15Answers: 0

    Thanks Allan.

This discussion has been closed.