<p>How are you inserting the data?</p>

<p>If you're inserting data through any of Craft's <a href="http://buildwithcraft.com/classreference#craft.app.records" rel="nofollow">Active Record</a> or <a href="http://buildwithcraft.com/classreference/etc/db/DbCommand" rel="nofollow">DbCommand</a> classes (<code>craft()-&gt;db-&gt;createCommand()</code>), then Craft will take of updating <code>dateUpdated</code> for you.</p>

<p>If you're using raw SQL, then you'll have to keep track of it yourself.</p>

CC BY-SA 3.0
2015-03-11T23:22:06.880Z
Ah, that makes sense. In prototyping I updated a record through phpMyAdmin and noticed it didn't have the `on update CURRENT_TIMESTAMP` attribute. If it's taken care of with `update()` it's fine.
Brett DeWoody
CC BY-SA 3.0
2015-03-11T23:18:49.430Z
2015-03-11T23:18:49.430Z
Brad Bell
<p>When creating a record in a plugin it automatically creates <code>dataCreated</code> and <code>dataUpdated</code> columns.  However, it doesn't look like the <code>dataUpdated</code> columns is updated <code>on update</code>. </p>

<p>Is there a way to set the <code>dataUpdated</code> column attribute to <code>on update CURRENT_TIMESTAMP</code>?</p>

<p>Or is that column manually updated in the background when using active record's <code>update()</code>?</p>

<plugin-development><database><records>
Plugin: Making a record's dateUpdated column update to CURRENT_TIMESTAMP
# Plugin: Making a record's dateUpdated column update to CURRENT_TIMESTAMP

(Asked by: username_0 on 2015-03-11)

When creating a record in a plugin it automatically creates `dataCreated` and `dataUpdated` columns. However, it doesn't look like the `dataUpdated` columns is updated `on update`.

Is there a way to set the `dataUpdated` column attribute to `on update CURRENT_TIMESTAMP`?

Or is that column manually updated in the background when using active record's `update()`?

**Tags:** plugin-development, database, records


---

## 1 answers

### Answer by username_1 on 2015-03-11. Score: 3 | Accepted answer

How are you inserting the data?

If you're inserting data through any of Craft's [Active Record](http://buildwithcraft.com/classreference#craft.app.records) or [DbCommand](http://buildwithcraft.com/classreference/etc/db/DbCommand) classes (`craft()->db->createCommand()`), then Craft will take of updating `dateUpdated` for you.

If you're using raw SQL, then you'll have to keep track of it yourself.

> **Comments:**
> **username_0**: Ah, that makes sense. In prototyping I updated a record through phpMyAdmin and noticed it didn't have the `on update CURRENT_TIMESTAMP` attribute. If it's taken care of with `update()` it's fine.  

---

