PLSQL – How to Compare Dates on Minute Level

oracleplsql

If I'm correct, then date comparison on seconds level is as simple as

SELECT 1
FROM sample_table
WHERE sysdate <= sample_table_date_field;

but haven't found any simple or stable solution for date comparison on minute level.
If there is, then what would it be?

Best Answer

You can use TRUNC (date) function which returns date with the time portion of the day truncated to the unit specified by the format model.
Syntax:

TRUNC(date, fmt) or TRUNC(date).

Where fmt can be 'DAY', 'YEAR','HH','MI'.
For more format model please refer: ROUND and TRUNC Date Functions
Example:

SELECT 1 FROM sample_table WHERE TRUNC(sysdate,'MI')<=TRUNC(sample_table_date_field,'MI');

Otherwise you can also use EXTRACT function to extract the elements from datetime.
Example:

SELECT 1 FROM dual WHERE extract(minute from systimestamp)=extract(minute from systimestamp);