[Rails] timestamp in PGSQL problems

Scott Barron scott at elitists.net
Thu Dec 9 13:28:03 GMT 2004


On Thu, Dec 09, 2004 at 11:29:41PM +1100, Bruno Mattarollo wrote:
> Hello,
> 
> I need to ask this to the list because I am not getting answers on the 
> IRC channel... I have a PGSQL DB where I have some columns defined as 
> "timestamp". When I display the object.posted_on on Rails, it shows:
> 
> Posted On Sat Jan 01 23:24:30 EST 2000

This is from ruby's Time class.  PostgreSQL's timestamps are converted
to Time objects in AR.  You can use Time#strftime to format timestamps
pulled from the DB.

> When the DB record has: 2004-12-09 23:24:30.957275

This is how postgresql displays them, it's just different from Time's
#to_s.

> I have tried "timestamp with time zone" but that doesn't change this 
> behavior. Even when I store Time.now on the column from my Rails 
> application, I still get this "Jan 01 2000" instead of the proper date 
> time.

I'm not quite understanding this.  Are you saying that putting Time.now
into a timestamp column then yields only the date portion?

-Scott


More information about the Rails mailing list