PDA

View Full Version : [SOLVED:] How to Find Oldest Date from various column of a record and calculate no. of days



winxmun
03-30-2016, 05:18 AM
Hi, May I know how to use query to find the oldest date from various column of a record and calculate number of days received based on oldest date of the record.
Based on table below, I would like to use the query to auto find "Oldest Date" and auto calculate "Aging". Thank you.



ID
ReceivedDate1
ReceivedDate2
ReceivedDate3
Oldest Date
Aging


1
01 Mar 16

02 Mar 16
01 Mar 16
29


2
02 Mar 16
02 Mar 16
04 Mar 16
02 Mar 16
28


3
03 Mar 16
01 Mar 16

01 Mar 16
29


4
01 Mar 16

01 Mar 16
01 Mar 16
29


5
04 Mar 16

03 Mar 16
03 Mar 16
27

ranman256
03-30-2016, 06:10 AM
youd make a separate query, that finds MIN date and id
SELECT table.ClientId, Min(table.[Date]) AS [MinOfDate] FROM table GROUP BY table.ClientId;

then join the table above to this query and calc age: DateDiff("d",MinOfDate,date)

winxmun
03-30-2016, 10:28 PM
thank you!