How do you set up a last updated function?
How do you set up a last updated function?
koniahin
Posts: 186Questions: 39Answers: 7
After editing a form I need to have it automatically update a field, last_updated, to the datetime like php now as you click to save. How do you do this?
This question has an accepted answers - jump to answer
Answers
If you are using MySQL, your last_updated field would update automatically if you have defined it correctly.
In the Editor world, you can also do it in the server-side scripts with Events - see the examples towards the end of this page,
Colin
I looked at the page but javascript especially is not my skillset. With the aid of other searches I did the following. For testing I added a new field called timestamp as:
Type: Timestamp
Default: current_timestamp()
I added the field in the Controller file:
Field::inst('articles.timestamp') ->set(function ($data) { return date('Y-m-d H:i:s'); }),
In the javascript file I added the field as:
{
label: "Current timestamp (field = timestamp)",
name: "articles.timestamp",
type: 'datetime',
def: function () {
return new Date(Date.now());
}
},
It is not updating the timestamp which we want to include HH-MM-DD.
You only need the timestamp field in your MySQL, and for queries. You don't want to edit it.
MySQL should look like this:
You should really be looking at MySQL sites. This is not a Datatables issue.
What is the command line alter table statement?
alter table articles change timestamp timestamp ..........
See the MySQL reference for
ALTER TABLE
here.Allan
My partner solved this by changing the Field in the controller file to:
Field::inst('articles.modified')->set( Field::SET_EDIT ),
The field type is date which is fine for what we need. Can you mark this as closed by the poster?
Good to hear that you've got a solution. That's your answer marked as the right one.
Allan