How to script "If file-creation-date precedes 1 January 2011 then"?

This should be simple, but I don’t see how to do it, and will be grateful for any help.

I’m working on a script that will automatically update a file (a folder action script) if the version of the file that is already on the disk has a creation date before 1 January 2011.

Is there a simple way to script “if the creation date of targetFile is before 1 January 2011 then…”??

If so, I will be very glad to learn how to do it. Thanks for any help.

Hi,

assuming theFile is an alias specifier


set firstJanuary2011 to date "1/1/2011" -- this changes to a localized string while compiling

if (creation date of (info for theFile)) comes before firstJanuary2011 then
	-- do something
end if

Allow me to pick a nit.
This only compiles by accident.
“1/31/2011” won’t compile when your Mac uses the dd/mm/yyyy format.

Thank you both for showing me how to do this. On my US system, with the date format as dd/mm/yyyy, this code seems to compile and work correctly:

set firstJanuary2011 to date "1 January 2011" -- can also be "January 1, 2011" but NOT "2011 January 1"

if (creation date of (info for theFile)) comes before firstJanuary2011 then
   -- do something
end if

Unless I’m missing something, this is exactly what I asked for. Thank you for showing how simple and straightforward it is.