Search code examples
rubypostgresqlpg

What is the "-400", "-500" following the date in Time.now in ruby and is date compatible with postgres date field?


Ruby and postgres question: I am wanting to insert the date from a Ruby script into a postgres database. The database date format is: 2013-03-13 17:08:51.207184-04 in postgres. BTW, what is "51.207184-04" in the date field in the Postgres database?

I want to write the data from ruby into the date column in postgres. I am assuming I need to use Time.now but I have no idea what that is? Whats up with the -400 or -500 at the end of the date time?

The postgres database field is: timestamp without time zone NOT NULL


Solution

  • In both cases, the last bit is a timezone, expressed as hours relative to UTC.

    I believe the PG timetamp shown is 2013-03-13 17h 08m 51.207184s at 4 hours behind UTC (but I'm not 100% familiar with postgres's field formats); in Ruby -0400 on the end of Time.now means the same, and -0500 means 5 hours behind.