Sorting Files by Date


Is there a way to sort files using the date in the title?

I want a chronological order using the date in the title, not date created, modified, etc.


At the moment this last file would be listed in between the first and second file.

I’m sure it can be done, but I’ve become thickheaded to the solution.


1 Like

To enable this when may be needed I always use a YYYY-MM-DD naming convention for files, titles, etc. Only easy way I know. Habitually have done this for years.

As I see it, you have two options:

  • (automatically) extract the date from the title and set that date as a sortable date (e.g. the created date)
  • (automatically) rename your files to use the format suggested by @rmschne

Both could easily be done with a smart rule or script, if the format is always the same (that is, ends - as do your three examples above - with a date in the format dd-mm-yyyy).

Hi @GlitteringWaters

Re @Blanc’s option 1 - below is a script adapted from (I think) one of DT’s stock scripts which I use to do something similar. (I can’t really script, so apologies in advance - others who can will be able to come up with a better solution).

I habitually use the YYYY-MM-DD convention like @rmschne but I often get large numbers of documents from solicitors with the document date in DD.MM.YYYY format at the end of the file name. I put it in Keyboard Maestro to set the Creation Date to the date appended to the file name. Once you have set the Creation Date (or you could use a custom data field if you don’t want to mess with the Creation Date), you can use a smart rule to rename the file using a placeholder. You could replace the “.” with “-” to fit with your naming convention.

-- Set creation date based on name "NAME DD.MM.YYYY”

tell application id "DNtp"
		set theRecords to selected records
		if theRecords = {} then error "Please select some records"
		show progress indicator "Renaming... " steps (count theRecords) as string with cancel button
		repeat with thisRecord in theRecords
			set thisName to name without extension of thisRecord
			step progress indicator thisName
			set theCreationDate to creation date of thisRecord
				set seconds of theCreationDate to 0
				set minutes of theCreationDate to 0
				set hours of theCreationDate to 0
				set day of theCreationDate to ((characters -10 thru -9 in thisName) as string) as integer
				set month of theCreationDate to ((characters -7 thru -6 in thisName) as string) as integer
				set year of theCreationDate to ((characters -4 thru -1 in thisName) as string) as integer
				set creation date of thisRecord to theCreationDate
			end try
		end repeat
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Please see Problems to set creation date from the file name on import, when the date is the 31st day of the month

Thanks, @pete31 - so I have it backwards? I should set year, then month, then day?
Good to know - thanks for the pickup.

In addition to the ideas here about writing scripts to convert the text representations of dates into sortable information, my needs for this are mostly met when I use Hazel’s text matching and date formatting capabilities to create sortable dates on incoming files. This handy for when I’m using Hazel to pre-process “easily-automateable” invoices/bills where the files are processed (named, tagged, etc.) based on content. Yes, can use DEVONthink for that, but for pre-processing files Hazel as a file processor seems easier to me. Your mileage may be different.

That’s fantastic, thank you all.