Jan 3, 2012

Time Zones in Rails using Postgres


It appears that by default Rails creates it's timestamps in Postgres using timestamps without time zone information.  This means that if you're working directly with the database, using psql for example, and want to see local time representations you'll have to do something like this.

Specifically notice that I'm using the TIMEZONE function to re-cast the column to a timestamp with timezone.  Since the columns implied timezone is 'UTC' that's what's used.  Now that we have a timestamp with timezone we can convert that to local time using the "AT TIME ZONE" syntax.


1 comment:

Kyle Daigle said...

After spending a good hour trying to figure this out, I finally found this post. Just wanted to +1 this.