Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Create custom date queries for Spotlight System 10.4
Tiger only hintIf you have the desire to create a Raw Query for a Smart Folder that uses dates, here is how to do it. From the first drop down menu in the Smart Folder window, choose Other, then choose Raw Query, or whatever the appropriate tag is (check "Add to Favorites" if you use this a lot). Now enter an expression that compares a date metadata field to $ For example:
kMDItemAttributeChangeDate >= $
This will return all things whose attributes were created or changed in the last week (7 days). You could use this to create a Smart Folder which only shows files you've downloaded in the past seven days, as kMDItemAttributeChangeDate reflects when the file was added to the Spotlight database.

If you want to use a specific date, you need to do it in format that Spotlight understands. I would recommend first creating a Smart Folder with Last Opened, Exactly, and then put your date there. Save your folder and then open it in Text Edit. To do this, run Text Edit, then drag the folder to Text Edit's icon in the Dock. You can then search for the string RawQuery and browse through the line. You will see something like:
kMDItemFSContentChangeDate >= 137304000 && kMDItemFSContentChangeDate < 137390400
These are the system times on either end of the day you entered in the Smart Folder. You want to copy these to the Raw Query field, and edit them to reflect the attributes you wish to search on. The HTML entities need to be replaced, too:
>=; becomes >=
&& becomes &&
<=; becomes <=
You can play around with looking at other auto-generated queries in Text Edit, and then modify them using the Finder's interface to make custom queries.
  • Currently 2.67 / 5
  You rated: 1 / 5 (6 votes cast)

10.4: Create custom date queries for Spotlight | 3 comments | Create New Account
Click here to return to the '10.4: Create custom date queries for Spotlight' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Create custom date queries for Spotlight
Authored by: jasenko on May 19, '05 11:07:23AM

Even more useful for me was to use $ function. Spotlight is a perfect tool to see what files new application are installing and where. Change the NUMBER with the number of seconds (I use last three hours so the number is -10800)

[ Reply to This | # ]
10.4: Create custom date queries for Spotlight
Authored by: dtrevas on May 20, '05 06:51:14PM

What this line

kMDItemFSContentChangeDate >= 137304000 && kMDItemFSContentChangeDate < 137390400

seems to be is the number of seconds since January 1, 2001 and I am guessing that it means midnight GMT.

One way to do this is a slightly less cryptic notation. You could write $time.iso(20050509T000000) where the T separates the date from the time.

2005 This year
05 May
09 the day of the month
00 midnight hour
00 minute
00 second.

One day some genius is going to let us write something like "kMDItemFSCreationDate between 5/9/05 and 5/11/05 at 4 pm CDT."

[ Reply to This | # ]
10.4: Create custom date queries for Spotlight
Authored by: lapidary on Jan 14, '06 06:11:52AM
do you know what ISO 8601 dates includes?
wikipedia has a good summery of it.
While it isn't exactly like you want, it's not as complacated as you thought when you orginally posted it.
take close notice to the fact it assumes local TZ.

[ Reply to This | # ]