# Current date/time - how to store with comments?

**URL:** <https://www.ruby-forum.com/t/current-date-time-how-to-store-with-comments/76528>\
**Category:** Rails\
**Created:** [March 4, 2006, 5:27am UTC](https://www.ruby-forum.com/t/current-date-time-how-to-store-with-comments/76528 "2006-03-04T05:27:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hreyaatnh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hreyaatnh](https://www.ruby-forum.com/u/hreyaatnh)\
**Post date:** [March 4, 2006, 5:27am UTC](https://www.ruby-forum.com/t/current-date-time-how-to-store-with-comments/76528/1 "2006-03-04T05:27:03Z")

</div>

Can someone tell me how to store the current date/time when someone  
posts a comment on my blog? I could even update the comments table  
after the comment is saved in the controller, but I’m not sure how to do  
that either.

Thanks for any help…

---

<div class="post-metadata">

**Author:** ![hreyaatnh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hreyaatnh](https://www.ruby-forum.com/u/hreyaatnh)\
**Post date:** [March 4, 2006, 5:33am UTC](https://www.ruby-forum.com/t/current-date-time-how-to-store-with-comments/76528/2 "2006-03-04T05:33:38Z")

</div>

Create a field called created\_at and/or updated\_at and Rails will do  
it all automatically. Make sure it’s a datetime (that’s in postgres,  
not sure what the mysql equivalent is).

You can also just make a datetime field called whatever you want, and  
do something like:  
comment.posted\_at = Time.now

and save it yourself…but it’s easier/more railsy to just use the  
“magic” fields created\_at/updated\_at.

Pat

---

<div class="post-metadata">

**Author:** ![hreyaatnh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hreyaatnh](https://www.ruby-forum.com/u/hreyaatnh)\
**Post date:** [March 4, 2006, 5:34am UTC](https://www.ruby-forum.com/t/current-date-time-how-to-store-with-comments/76528/3 "2006-03-04T05:34:25Z")

</div>

Thanks, that was easy!
