Skip to content

Instantly share code, notes, and snippets.

@glamp
Last active December 16, 2015 01:59
Show Gist options
  • Save glamp/5359212 to your computer and use it in GitHub Desktop.
Save glamp/5359212 to your computer and use it in GitHub Desktop.
select
date_trunc('year', '2013-04-05'::date) as year
, date_trunc('month', '2013-04-05'::date) as month
, date_trunc('day', '2013-04-05'::date) as day;
-- year | month | day
--------------------------+------------------------+------------------------
-- 2013-01-01 00:00:00-05 | 2013-04-01 00:00:00-04 | 2013-04-05 00:00:00-04
select
to_char('2013-04-05'::date, 'YYYY') as year
, to_char('2013-04-05'::date, 'MM-YYYY') as month
, to_char('2013-04-05'::date, 'YYYYMMDD') as day;
-- year | month | day
--------+---------+----------
-- 2013 | 04-2013 | 20130405
select
to_timestamp(1365560673);
-- to_timestamp
------------------------
-- 2013-04-09 22:24:33-04
select date_part('day', '2013-04-05'::date);
-- date_part
-------------
-- 5
select date_part('second', to_timestamp(1365560673));
--date_part
-------------
-- 33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment