date_part() works like extract() , i.e. it extracts a subfield from the source:
-- they will both yield 9 as result select date_part('day', date '2015-01-09') "day part of 2015-01-09", date_part('day', date '2015-02-09') "day part of 2015-02-09";
The extraction day(s) therefore not suitable for selecting the last 24 hours. Similarly, extracting hour(s) will (almost) always give less than or equal to 24 .
Extracting day(s) from interval (which is the result of subtracting 2 timestamp s) is slightly different. The result may depend on whether the interval is justified or not:
-- they will both yield 1 as result select date_part('day', interval '1 day') "day part of 1 day", date_part('day', interval '1 month 1 day') "day part of 1 month 1 day"; -- they will yield 1, 32 and 397 respectively select date_part('day', timestamp '2015-02-09' - timestamp '2015-02-08') "interval 1", date_part('day', timestamp '2015-02-09' - timestamp '2015-01-08') "interval 2", date_part('day', timestamp '2015-02-09' - timestamp '2014-01-08') "interval 3";
Depending on the fact that subtracting the timestamp does not give reasonable intervals, I do not think this is the best option. You can use simpler conditions to achieve your goal:
-- if startdate is a timestamp: where current_timestamp - interval '1 day' <= startdate -- if startdate is a date: where current_date - 1 <= startdate
If you want to also ban future dates (as your question suggests), you can use one condition between :
-- if startdate is a timestamp: where startdate between current_timestamp - interval '1 day' and current_timestamp -- if startdate is a date: where startdate between current_date - 1 and current_date