HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to compare dates on minute level in plsql?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
leveldateshowplsqlcompareminute

Problem

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?

Solution

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')

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);

Context

StackExchange Database Administrators Q#128166, answer score: 3

Revisions (0)

No revisions yet.