Ask Your Question
1

What is the method to use DateDiff calculation in Oracle's WHERE clause?

asked 2023-07-07 10:17:28 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-07 10:46:01 +0000

nofretete gravatar image

To use DateDiff calculation in Oracle's WHERE clause, you can use the following syntax:

SELECT * FROM tablename WHERE DATEDIFF('interval', date1, date2) = value;

Here, the 'interval' specifies the time unit such as day, hour, minute, etc. that you want to calculate the difference in. 'date1' and 'date2' are the two dates between which the difference needs to be calculated. 'value' is the numerical value that you are comparing the difference to.

For example, if you want to find all the records where the difference between the 'created_date' and the current date is greater than 30 days, you can use the following query:

SELECT * FROM tablename WHERE DATEDIFF('day', created_date, sysdate) > 30;

This will return all the records where the difference between the 'created_date' and the current date is greater than 30 days.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-07 10:17:28 +0000

Seen: 9 times

Last updated: Jul 07 '23