Using join to get date diff (Oracle)

Posted on 2010-01-05
Medium Priority
Last Modified: 2013-12-07

I want to use join or any method to get date diff by comparing the date in result of the following query with sysdate
 SELECT   COUNT (1) total, admin,DECODE (location, 'head', 'head', 'OUT') location,mydate
        FROM stocks
         WHERE status= 'PENDING' AND pending_with = 'user'  and location<>'head'
          GROUP BY mydate,m_admin,DECODE (location, 'head', 'head', 'OUT') ORDER BY admin, DECODE (location, 'head', 'head', 'OUT')

The result of this query is somthing like

TOTAL admin            location       mydate

1      user1       OUT      12/21/2009 5:58:41 PM
1      user1             OUT      12/26/2009 11:36:16 AM
1      user1             OUT      12/21/2009 6:00:40 PM
1      user1             OUT      12/21/2009 5:28:47 PM
1      user1             OUT      12/26/2009 11:33:04 AM
1      user1             OUT      12/29/2009 8:23:17 AM
1      user1             OUT      12/26/2009 10:54:29 AM

Now I want this query to be modified to get another value as duration which is a comparison between sysdate and mydate
datediff(dd,mydate,getdate()) as duration
but this gives error when  I put it in the query

Any idea on how to get it work.



Question by:zaki100
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 26180462
oracle does not have the "datediff" function...
you could just use this expression:

sysdate - mydate
LVL 15

Expert Comment

by:Shaju Kumbalath
ID: 26180540
or Trunc(sysdate)-trunc(mydate)
LVL 32

Expert Comment

ID: 26182636
Is this MS SQL Server or Oracle?

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question