Blog gw

mencari umur di postgre

Posted by dillah2008 on January 14, 2009

Postgre memiliki fungsi untuk mencari umur(malah mendetail sampai bulan dan harinya), berikut contoh SQL untuk menampilkan umur dalam tahun saja

select extract(year from age(access_stamp,birth_date)) as umur from tbl_cust where cust_code is not null and birth_date is not null order by umur

Contoh diatas adalah membandingkan dua buah field yaitu field access_stamp(bertipe date) dikurangkan dengan field birth_date(bertipe date). Jika untuk menampilkan full tahun bulan dan harinya hanya cukup menggunakan ini

select age(birth_date) from tbl_cust where cust_code is not null

Semoga bermanfaat :)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>