Converting a date to unix timestamp (epoch seconds)

You want to compare a Postgresql date or timestamp to a unix time (seconds since the epoch).

Solution

Use date_part() or extract() datepart-ref extract-ref.

Discussion

If you are planning to do a lot of temporal manipulation, always use Postgresql's date/time types - they offer better features. On the other hand, most client languages provide unix-style timestamps - these two functions can bridge the gap for you.

select date_part('epoch',now()) as unixtime;

select extract('epoch' from now()) as unixtime;