# RE: how to insert Current DateTime value into database?

**URL:** <https://www.ruby-forum.com/t/re-how-to-insert-current-datetime-value-into-database/56887>\
**Category:** Rails\
**Created:** [April 5, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/re-how-to-insert-current-datetime-value-into-database/56887 "2006-04-05T15:30:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Cherry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@Andrew\_Cherry](https://www.ruby-forum.com/u/Andrew_Cherry)\
**Post date:** [April 5, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/re-how-to-insert-current-datetime-value-into-database/56887/1 "2006-04-05T15:30:05Z")

</div>

If you simply want the time that a record was updated, simply add a  
field to the model table called “updated\_at”. It’ll auto-update on save.

---

<div class="post-metadata">

**Author:** ![Andrew\_Cherry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@Andrew\_Cherry](https://www.ruby-forum.com/u/Andrew_Cherry)\
**Post date:** [April 5, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/re-how-to-insert-current-datetime-value-into-database/56887/2 "2006-04-05T15:42:17Z")

</div>

It’s not rails-y, but I like having the db take care of this. If you’re  
using migration maybe it doesn’t matter, but if you’re defining your  
tables  
first, then you could define them like so.

updated TIMESTAMPTZ NOT NULL DEFAULT NOW(),

– TIMESTAMPTZ is postgresql-specific I believe.

This covers you if you have ever have non-ruby/rails updates to the  
table.

Is this basically what rails does under the covers?

thanks.
