At a guess, you're storing it with one timezone
setting and retrieving it with a different one.
For example, if Rails thinks you're in UTC+6:30 but PostgreSQL thinks you're in UTC+5:30, and if Rails sends dates to Pg timezone qualified but reads them from Pg with the assumption that they're in local time, this would happen. It's safest to make sure your database driver always reads and writes dates timezone-qualified.
Given the one hour gap, I'm wondering if daylight savings is involved, but it could also just be that your timezone is off by one hour.
regress=# create table test ( x timestamp with time zone );
CREATE TABLE
regress=# insert into test (x) values ('2012-08-09 12:00:00 UTC+6:30');
INSERT 0 1
regress=# SET TIMEZONE = '-5:30';
SET
regress=# select * from test;
x
---------------------------
2012-08-10 00:00:00+05:30
(1 row)
regress=# SET TIMEZONE = '-6:30';
SET
regress=# select * from test;
x
---------------------------
2012-08-10 01:00:00+06:30
(1 row)
Alternately, maybe your database is in time zone '-1:00' and your application is stripping off the time zone when it reads the date, so the date appears to be off by one hour. It's hard to say with the available information.
To really help you it would be necessary for you to show:
- The code that inserts the date
- The
INSERT
statement that really inserts the date, captured by enabling log_statement = 'all'
in postgresql.conf
, along with any SET TIMEZONE
statements that session ran before the INSERT
.
- The result of
SELECT
ing that column from the database after a SET TIMEZONE = 'UTC'
- and the code that reads the date