A
A
Anton2015-12-03 21:40:18
PostgreSQL
Anton, 2015-12-03 21:40:18

How to write timestamp to database (PostgreSQL)?

Hello!
The database has a last_date column with a timestamp type. It must contain the date and time, respectively.
I tried to insert in various ways, but nothing comes out. Only the year-month-day is updated, and everything else is zero-based.
2c0dd20cf8e94ef7b210a1efb19af56e.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dima, 2015-12-03
@MAXOPKA

If you have an `updated_at` field in your table, then use it, if not, then add it using this migration:

class AddTimestampsToUser < ActiveRecord::Migration
    def change_table
      add_column(:users, :created_at, :datetime)
      add_column(:users, :updated_at, :datetime)
    end
end

Datetime of record creation will be written in `created_at`, and datetime of record update (including when calling `update_attributes`) in `updated_at`

A
Alexey S., 2015-12-03
@Winsik

INSERT INTO t1 
 (timestamp_column) 
 VALUES 
 (TIMESTAMP '2015-12-03 21:54:38');

D
Dmitry Belyaev, 2015-12-03
@bingo347

So you haven't tried it?'2015-12-03 12:30:00.000000'::timestamp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question