user1551373
user1551373

Reputation: 151

FROM_UNIX alternate in PostgreSQL

Guys I have stored unix timestamps in my MySQL database, where I was reading them using the MySQL function FROM_UNIX().

Now I'm migrating the database from MySQL to PostgreSQL. In PostgreSQL, how I can read unix timestamps just like I was doing in MySQL with FROM_UNIX() ?

Upvotes: 7

Views: 18115

Answers (2)

baklarz2048
baklarz2048

Reputation: 10938

SELECT to_char(date(to_timestamp(1195374767)),'YYYY-MM-DD');
  • to_timestamp - convert to Postgresql timestamp no unix timestamp
  • date convert to date type
  • to_char format output

http://www.postgresql.org/docs/8.1/static/functions-formatting.html

extract can do the same thing but not in one step

Upvotes: 4

user330315
user330315

Reputation:

Taken from the manual:

to_timestamp(double precision) convert Unix epoch to time stamp

If you need parts of the created timestamp, use the extract function

select extract(year from to_timestamp(1284352323))

Upvotes: 8

Related Questions