1

I have a Log table and this is it's description:

user_id(bigint)
  time (bigint)

My question is, how can I extract the year from the time column in PostgreSQL?

This works in MySQL:

 SELECT l.user_id, year(from_unixtime(l.time)) 
 FROM log l;

2 Answers 2

3
select date_part('year', to_timestamp(1365682413));

to_timestamp is our friend here and has taken a unix time since at least version 8.1.

Sign up to request clarification or add additional context in comments.

Comments

1
select extract(year from timestamp 'epoch' + "time" * interval '1 second')
from log;

1 Comment

Thank you very much! I'm newbie in PostgreSQL, and this worked perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.