Bernardo Pedrosa
Bernardo Pedrosa

Reputation: 68

PostgreSQL Insert timestamp using today's date but specific hour

I had this statement for SQLSERVER which inserts into a DateTime column, today's date but a specific hour.

INSERT INTO session VALUES(
SMALLDATETIMEFROMPARTS(YEAR(GETDATE()), MONTH(GETDATE()), DAY(GETDATE()), 12, 0), 1, 1);

I am trying to achieve the same result in PostgreSQL but I can only find this

INSERT INTO sessions VALUES(current_timestamp, 1, 1)

Which inserts the current date and time.

How would I be able to do this in PostgreSQL?

Upvotes: 1

Views: 7927

Answers (2)

P113305A009D8M
P113305A009D8M

Reputation: 374

You can use like this :

NOW() + interval '12 hour'

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270653

You can use:

current_date + interval '12 hour'

Note: When you insert values into a table, you should always list the columns for the insert.

Upvotes: 2

Related Questions