postgresql date_part code example
Example 1: datepart postgres
SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40');
Result: 16
SELECT date_part('hour', INTERVAL '4 hours 3 minutes');
Result: 4
Example 2: DATE_SUB postgres
-- MySQL
DATE_SUB(NOW(), INTERVAL '1 YEAR')
-- PostgreSQL
(NOW() - INTERVAL '1 YEAR')