Skip to main content

postgresql_in_action

Get a field (year or month) from a date/timestamp

select id, dob, date_part('month', dob) as dob_month, date_part('year', dob) as dob_year
from member
where id = '5510416d-de95-5723-8c67-acab9a4bb1d5';

'5510416d-de95-5723-8c67-acab9a4bb1d5', '1993-11-16 00:00:00.000000', 11, 1993


select id, dob, dob::date as dob_date
from member
where id = '5510416d-de95-5723-8c67-acab9a4bb1d5';

5510416d-de95-5723-8c67-acab9a4bb1d5,1993-11-16 00:00:00.000000,1993-11-16