Robert Batchelor
asked on
How do I Sort by Calendar Date and Ignore the Year?
We have the arrival date (and in some cases the birth date) of several hundred equines (horses, donkeys, and mules) we have rescued in the last ten years. Each calendar day we want to remember/celebrate an equine that arrived (or its birthday, if known). So how do I sort my arrival date report by calendar day (month and day) and ignore the year it arrived (or was born)? I use MS Access 2007.
ASKER
Thank you. We are close but the dates are not in order (see attached report). Can you fix this?
My SQL:
SELECT tblHorses.strHorseBarnName , tblHorses.datDateFirstAcqu ired
FROM tblHorses
WHERE (((Format([tblHorses].[dat DateFirstA cquired]," mm"))=Form at(Date(), "mm")))
ORDER BY tblHorses.datDateFirstAcqu ired, Format([tblHorses].[datDat eFirstAcqu ired],"mm- dd");
-0Alphabetical-List-Entire-History-Sorte
My SQL:
SELECT tblHorses.strHorseBarnName
FROM tblHorses
WHERE (((Format([tblHorses].[dat
ORDER BY tblHorses.datDateFirstAcqu
-0Alphabetical-List-Entire-History-Sorte
Should be:
Order by Format(...
Leave out the first part
From my iPhone
Order by Format(...
Leave out the first part
From my iPhone
ASKER
Thanks, that worked:
SELECT tblHorses.strHorseBarnName , tblHorses.datDateFirstAcqu ired
FROM tblHorses
ORDER BY Format([tblHorses].[datDat eFirstAcqu ired],"mm- dd");
But would if just want the horses for the current month only?
SELECT tblHorses.strHorseBarnName
FROM tblHorses
ORDER BY Format([tblHorses].[datDat
But would if just want the horses for the current month only?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
This worked for the current month only:
SELECT tblHorses.strHorseBarnName , tblHorses.datDateFirstAcqu ired
FROM tblHorses
WHERE Month([tblHorses].[datDate FirstAcqui red])=Mont ht(Date())
ORDER BY Day([tblHorses].[datDateFi rstAcquire d]);
This worked for the current month only:
SELECT tblHorses.strHorseBarnName
FROM tblHorses
WHERE Month([tblHorses].[datDate
ORDER BY Day([tblHorses].[datDateFi
FROM yourTable
WHERE Format([ArrivalDate], "mm") = Format(Date(), "mm")
ORDER BY Format([ArrivalDate], "mm-dd")
This will give you the name and arrival date of each animal which arrived during the current month, ordered by the date as month-day. You need the two character "mm" and "dd" values or the values for 10 will immediately follow those for 1.