Timestamp upon update

Timestamp upon update

DealogicDealogic Posts: 5Questions: 0Answers: 0
edited May 2013 in Editor
Hi,

using editor with MySQL. I'd like to have a new column, where a timestamp is inserted every time someone updates a record (basically even the current date is enough too). How could this be achieved in the easiest way, what part(s) of the code should be modified?

Thanks in advance for the answers.

Cheers

p.s. DataTables is great, gives a plethora of options.

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Since you are using MySQL you could use the `ON UPDATE CURRENT_TIMESTAMP` option in your schema ( http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html ).

    The other option is to have a field defined in the Editor libraries (assuming you are using them) as add the timestamp to the data to be processed by the Editor libraries, before it does the processing (i.e. add it to _POST - or safer, a copy of _POST).

    Allan
  • DealogicDealogic Posts: 5Questions: 0Answers: 0
    Thanks!

    Did it the first way.

    Do you know what should be done if i wanted to have only the date inserted (and not the date and time)?

    It would be enough just to see the date in the table/editor itself - can/should something be done to the script/database itself?

    Cheers
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    You could use a trigger in the database that will automatically insert the current date, or you could use the additional field method I suggested before, with the value effectively filled in by the server-side script.

    Allan
  • DealogicDealogic Posts: 5Questions: 0Answers: 0
    Many thanks for the help!
This discussion has been closed.