0

I have a table EMPLOYEE_STATUS, with column SUBMIT_DATE values as 11-05-18 11:27:34.086000000 AM and UPDATED_ON values as 11-06-18 12:55:22.064000000 PM which is basically current date.

I need a sql query for oracle database to find those rows where difference in days between submited date and updated on or current date is 30 days or more. I tried DATEDIFF function but couldnt able to make it work.

I have tried the following (which does not work):

select * from EMPLOYEE_STATUS e 
where DATEDIFF(month, '12-06-18 03:34:09.448000000 PM', e.SUBMIT_DATE) >=1
shrikant.sharma
  • 203
  • 1
  • 17
  • 37

1 Answers1

-1

The function DATEDIFF() is not included in Oracle SQL server (as mentioned in this post). Instead you simply subtract the dates from each other, like this:

SELECT (11-06-18 12:55:22.064000000 PM) - (11-05-18 11:27:34.086000000 AM);

Which returns the difference in days. So you have to compensate for that (in your example, you are looking for a difference of a month, which could be anything between 28 and 31 days).

For those using MySQL or SQL Server, you can do it like this:

SELECT DATEDIFF(month, '2018-05-11 11:27:34', '2018-06-11 12:55:22') AS DateDiff;
Jakob Busk Sørensen
  • 5,599
  • 7
  • 44
  • 96