Question

If I have a function in PL/pgSQL that takes in a timestamp, what is the best way to identify whether that date is less than 12 months in the past?

e.g.

CREATE FUNCTION do_something(foo timestamp) ....
    -- IF foo is less than 12 months in the past THEN
    --    do something
    -- END IF;
END;
Was it helpful?

Solution

Read about intervals on PostgreSQL doc: Date Types. Use something like:

where foo < CURRENT_TIMESTAMP - interval '12 months'

OTHER TIPS

Or, equivalently: age(foo) < interval '12 months'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top