Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find the first previous date from the last date?

Status
Not open for further replies.

Hamboneman

Technical User
Apr 1, 2002
3
US
I am working on a Preventive Maintenance Database and want to compare the last date of PM to the previous date of PM from a table with completed PM data. I can query to get the date of the last PM, but how do I query to get the date of first PM previous to the last?
 
Write a query, qPMLast say, to return your latest pm date:

select max(pmdate) as lastPMDate
from pmdata

Then

select max(pmdata.pmdate) as secondlastPMDate
from pmdata, qPMLast
where pmdate < qPMLast.lastPMDate Best Regards,
Mike
 
I have a query of a table of completed Preventive Maintenance with dates, serial #'s and hour meter readings. I group that query using group by last date and end up with the most recent PM date for each serial number. I need to query for the next to last PM, so I can subtract the next to last date from the last date, so I can compare that to what we were supposed to do by number of days.
 
mdthornton's solution should get you what you want. Another option would be to use dmax()=(speed killer)
dmax([pmdate],&quot;tablename&quot;,&quot;serialnumer = 123 and date < query.maxdate)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top