# Rails date conversion

**URL:** <https://www.ruby-forum.com/t/rails-date-conversion/172835>\
**Category:** Rails\
**Created:** [July 28, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/rails-date-conversion/172835 "2009-07-28T19:28:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [July 28, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/rails-date-conversion/172835/1 "2009-07-28T19:28:39Z")

</div>

The environment.rb file in a Rails 2.3.2 app says:

> Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.

Auto-convert to this zone… when?

Also, what are the differences between these two statements?

config.time\_zone = xxx  
config.active\_record.default\_timezone = xxx

I ask these questions because I have a scenario whereby an AR-backed  
object, when issued the “published\_at” method yields a date like “Tue  
Jul 28 17:04:58 UTC 2009”. However, when _finding_ the object, e.g.  
Object.first, I get what looks like a UTC date: “2009-07-28 17:07:11”.  
(That is, when you find an object in console it shows you all its  
attributes, and it is in there that I have what I think is a UTC date.)

So… what’s the deal?

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [July 29, 2009, 4:43pm UTC](https://www.ruby-forum.com/t/rails-date-conversion/172835/2 "2009-07-29T16:43:27Z")

</div>

On Jul 28, 1:28 pm, Daniel W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I ask these questions because I have a scenario whereby an AR-backed  
> object, when issued the “published\_at” method yields a date like “Tue  
> Jul 28 17:04:58 UTC 2009”. However, when _finding_ the object, e.g.  
> Object.first, I get what looks like a UTC date: “2009-07-28 17:07:11”.  
> (That is, when you find an object in console it shows you all its  
> attributes, and it is in there that I have what I think is a UTC date.)
> 
> So… what’s the deal?

See:  
[http://ryandaigle.com/articles/2008/1/25/what-s-new-in-edge-rails-easier-timezones](http://ryandaigle.com/articles/2008/1/25/what-s-new-in-edge-rails-easier-timezones)

Essentially, times recorded in the database by AR are now always in  
UTC. The default time\_zone is used to convert the DB values from UTC  
for local display. The default TZ can be dynamically overridden in  
the application to permit individual users to have times displayed in  
their own locale TZ.

HTH
