Using SetFile to change file creation date produces wrong date

I have a PDF file for which I'd like to change the creation date to Dec. 4, 1948. I have the developer tools. I loaded up Terminal and typed:


SetFile -d '12/04/1948 12:00:00' filename.pdf


But it changed the creation date to Jan. 9, 2085 instead. I wonder if it sees '12/04/1948' and rather than seeing a date it does some calculation instead, arrives at a number, and maybe moves the file's date forward for that number of days? Well, I'm not sure what's happening.


If I surround the date and time with a double-quote instead of single-quote the same thing happens.

iMac 24″

Posted on Feb 28, 2024 9:15 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 28, 2024 10:31 AM

If you read the man page for SetFile, it states that the date must be in the UNIX Epoch timeframe (1/1/1970 - 1/18/2038) — because macOS is a UNIX operating system. Your 1948 year value sends SetFile into a deranged fit.

10 replies

Feb 29, 2024 12:02 AM in response to rick7

FileCreateDate 1970:01:01 00:00:00 UTC is the earliest date macOS 14 (or any UNIX?) supports. Some apps like GraphicConverter might temporarily set it to an earlier date in Finder dates but usually after a reboot it is changed to some weird future date.


On the other hand, the earliest FileModifyDate seems to be something like 1677:09:21 01:52:33+01:40 (YMMV, the exact time might depend on your location and timezone).


In movies the earliest QuickTime:CreateDate is 1904:01:01 01:39:50+01:39 (again YMMV).


In movies as early as Keys:CreationDate 0001:01:01 00:00:00 works for Photos.app. Google Photos might randomly display a wrong date and even if it displays the correct date, it might sort that movie incorrectly so I use 1902 as the earliest date in Google Photos.


In images ExifIFD:DateTimeOriginal 0001:01:01 00:00:00 seems to be the earliest that Photos.app supports. Google Photos accepts EXIF dates after 01.01.1902 (EXIF date 01.01.1901 08:00:00 is displayed as 06.12.1969 21:09:00).


BTW Windows seems to have yearly creep with the file system timestamps. A few months ago the date had crept up to 1973:12:31 23:59:59.


https://exiftool.org/forum/index.php?topic=15354.msg82435#msg82435

Feb 28, 2024 11:26 AM in response to rick7

Another approach is to use Apple's Preview to assign that data string as a new PDF keyword attribute via the Inspector panel.



Once that is done, you can locate that PDF easily with the following Spotlight search:



I suggested the PDF Keyword attribute as it is within the PDF and not associated with the file as an extended attribute (e.g. Finder comment). The latter can get stripped from a document depending on its cross-platform travels, but the internal PDF keyword attribute is immune.

Feb 29, 2024 1:41 PM in response to VikingOSX

Thanks for the note about adding Keywords to .pdf via Preview.app.


I have been using exiftool for this. Preview.app can read them and vice versa.


Writing Keywords as a comma-separated list to .pdf metadata can be done in exiftool with the following command:


exiftool -overwrite_original_in_place -sep ', ' -PDF:Keywords='Keyword 1,Keyword 2' a.pdf


Which reads as:


exiftool -a -G1 -s a.pdf                                                        
[PDF]           Keywords                        : Keyword 1, Keyword 2


Add Keywords:


exiftool -overwrite_original_in_place -sep ', ' -PDF:Keywords+='Keyword 3,Keyword 4' a.pdf

exiftool -a -G1 -s a.pdf                                                                 
[PDF]           Keywords                        : Keyword 1, Keyword 2, Keyword 3, Keyword 4


Remove a Keyword:


exiftool -overwrite_original_in_place -sep ', ' -PDF:Keywords-='Keyword 2' a.pdf


https://exiftool.org/TagNames/PDF.html

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using SetFile to change file creation date produces wrong date

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.