Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Monday, June 17, 2013

Converting date in PostgreSQL

Get current date, month, and year (return type is DOUBLE PRECISION) :
                     
select EXTRACT(DAY FROM now());

select EXTRACT(MONTH FROM now());

select EXTRACT(YEAR FROM now());


Get current date, month, and year (return type is TEXT) :
select to_char(now(), 'YYYY'); -- year (4 and more digits)

select to_char(now(), 'MM');  -- month number (01-12) with leading zero

select to_char(now(), 'DD');  -- day of month (01-31) with leading zero


For complete complete documentation : to_char