Tag a file depending on date range

I want to tag PDF files with a UK tax year based on a date range in the title or from the contents.

i.e a file that starts with the name ‘2018-04-06’ to ‘2019-04-05’ should have the tag 2018-19 and a file with a name that starts with ‘2017-04-06’ to ‘2018-04-05’ should have the tag 2017-18

I use Hazel to rename the file based upon the date within the PDF.


If I understand what you’re asking for, Hazel can do this for you. You can use the “matches” or “contain match” conditions to get the date from the filename or contents. Check to see if it’s within a given tax year, then set the tag based on the appropriate year. You will need one rule per tax year (if you were tagging based on calendar years I think you could get one rule that would tag files from any year appropriately).

I have no idea how UK tax years work, so the example uses the US Federal Fiscal Year, with which I am painfully familiar. :slightly_frowning_face:

Thats great but I wanted to avoid having multiple rules. If there isn’t a way within one rule then I guess I will have to use multiples.