adding a timestamp in data entries

adding a timestamp in data entries

Reefo Relaxo
Number of replies: 2
Hi, I'm not sure if this is the right forum to ask this. 

But I created a form and I need that form to have a timestamp on the database.
"When was the form created?"
And I need the Date and Time to be displayed also in human readable when I called the table.

I'm new at moodle programming and programming in general.

THANKS IN ADVANCE.
평균 등급 : -
In reply to Reefo Relaxo

Re: adding a timestamp in data entries

Leon Stringer
Core developers 사진 Particularly helpful Moodlers 사진

Many database tables in Moodle have a timecreated and timemodified column.

When creating a new record you can do:

$record->timecreated = time();
$record->timemodified = $record->timecreated;
$DB->insert_record('mytable', $record);

And when updating a record do:

$record->timemodified = time();
$DB->update_record('mytable', $record);

That way the record stores the date/time when it was created, and the date/time it was last modified.

In the database Moodle stores date/time as a Unix epoch value. You can use userdate() to show these values in the a human-readable format.

See the Time API page in the dev docs for more information.

평균 등급 :Useful (1)