# Setting updated\_at in database

**URL:** <https://www.ruby-forum.com/t/setting-updated-at-in-database/159201>\
**Category:** Rails\
**Created:** [February 2, 2009, 11:19am UTC](https://www.ruby-forum.com/t/setting-updated-at-in-database/159201 "2009-02-02T11:19:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 2, 2009, 11:19am UTC](https://www.ruby-forum.com/t/setting-updated-at-in-database/159201/1 "2009-02-02T11:19:06Z")

</div>

Hi,  
I have an ‘updated\_at’ field in events table. Whenever I am creating  
an event it gets set to Time.now. But I don’t want to set current time  
in it. But I want to set another time. How should I do that? I tried  
like this:-

event.updated\_at=“2008-02-02 03:35:11”.  
event.save

Still it not working.  
Can anyone tell me how to do that?  
Thanks,  
Tushar

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 2, 2009, 11:51am UTC](https://www.ruby-forum.com/t/setting-updated-at-in-database/159201/2 "2009-02-02T11:51:38Z")

</div>

You can’t without executing the sql directly, because updated at is  
automagic

Sent from my iPhone

On 02/02/2009, at 9:19 PM, Tushar G.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 2, 2009, 12:15pm UTC](https://www.ruby-forum.com/t/setting-updated-at-in-database/159201/3 "2009-02-02T12:15:46Z")

</div>

you can try overriding the method that is setting the updated\_at  
attribute. take a look at this (which is the first hit google found  
for me on that subject):  
[http://neeraj.name/blog/articles/800-override-automatic-timestamp-in-activerecrod-rails](http://neeraj.name/blog/articles/800-override-automatic-timestamp-in-activerecrod-rails)

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 2, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/setting-updated-at-in-database/159201/4 "2009-02-02T12:22:16Z")

</div>

On Mon, Feb 2, 2009 at 12:19 PM, Tushar G. \<  
removed\_email\_address@domain.invalid\> wrote:

> ## Still it not working. Can anyone tell me how to do that? Thanks, Tushar
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

Think about why you want to do this. The updated\_at column is an  
automatic  
column that is meant to provide the date and time the entry was last  
modified.  
If you need to set a different date/time, why not create a new field  
with a  
new name and then set it manually or you can auto set it in a  
before\_save  
method with your own business logic.

–  
Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 2, 2009, 12:58pm UTC](https://www.ruby-forum.com/t/setting-updated-at-in-database/159201/5 "2009-02-02T12:58:01Z")

</div>

MaD wrote:

> you can try overriding the method that is setting the updated\_at  
> attribute. take a look at this (which is the first hit google found  
> for me on that subject):  
> [http://neeraj.name/blog/articles/800-override-automatic-timestamp-in-activerecrod-rails](http://neeraj.name/blog/articles/800-override-automatic-timestamp-in-activerecrod-rails)

That seems to be not working for me.

I have column name as “date\_modified” instead of “updated\_at”.  
I done everything that is given their.
