Link to home
Start Free TrialLog in
Avatar of CraigBFG
CraigBFG

asked on

Number of days between 2 dates

I need to be able to show the number of days between 2 dates, but only for items with Status=Closed.

Days = DateClosed-Timestamp

This is to be incorporated into an existing custom query within FP2002. So ultimately, the resulting table shows me :-

Category - Total - Qty Open - Qty Closed - Avg Days Open

SELECT DefCat as Category,
Count(DefCat) as Total,
Sum(Right([Status]='open',1)) as Open,
Sum(Right([Status]='closed',1)) as Closed
FROM tblDefect
WHERE (AddID = ::AddID::)
GROUP BY DefCat
ORDER BY DefCat ASC;

Thank - Craig
ASKER CERTIFIED SOLUTION
Avatar of CRagsdell
CRagsdell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CraigBFG
CraigBFG

ASKER

Didn't work straight away, had to change double quotes to single quotes. Also was missing an aggregate function at the beginning of the statement like count or sum, so I plumpled for AVG which is what I wanted.
Thanks.


final query looks like :-

SELECT DefCat as Category,
Count(DefCat) as Total,
Sum(Right([Status]='open',1)) as Open,
Sum(Right([Status]='closed',1)) as Closed,
Avg(DateDiff('d', Timestamp, DateClosed)) as Days
FROM tblDefect
WHERE (AddID = ::AddID::)
GROUP BY DefCat
ORDER BY DefCat ASC;