How To Change File Creation Dates To Match Photo Metadata

When you export photos from the Photos app the date of the file doesn't match the date the photo was taken. This is correct as the file is new and the photo in it does retain the metadata with the original date. But if you want to force the file date to match the photo date, you can do it in the Terminal or with an Automator app.



Here’s the code used in this tutorial:

for f in "$@"
do
	touch -t $(date -j -f "%Y%m%d%H%M" -v-6H $(mdls $f | grep kMDItemContentCreationDate | head -n1 | awk '{gsub("[^[:digit:]]+"," ");print $1$2$3$4$5}') +%Y%m%d%H%M
202105271859) $f
done

Comments: 11 Responses to “How To Change File Creation Dates To Match Photo Metadata”

    Douglas Brace
    5 months ago

    Is it possible to do this so that the creation date is changed but not the modified date? Why am I asking? Technically speaking someone might want the creation date to be the actual original date and time from when the photo was taken but might want the modified date to be when the photo was exported (in this case, since the original was an HEIC file the export would be the JPEG version of it). If it is possible, thanks in advance. If not, I completely understand and I appreciate everything.

    5 months ago

    Douglas: That will take much more work. You’d have to save the original modified date to a variable, then recall it and set the modified date after setting the primary date.

    Dan
    4 months ago

    Amazing Thank You!
    Just what I was looking for. All other guides was only about changing the date manually one file at a time.
    With this Automator I can now change thousands of files by select and drag.

    iPhone Photo app seems not to care about true metadata, and uses the file created date instead, when transferring backed up photos and videos back to iPhone.

    Craig
    4 months ago

    Will this work for .mov files?

    4 months ago

    Craig: Theoretically yes. But video file metadata is different so you’ll need to research the correct things to address and perhaps do some trial and error.

    Victor
    1 month ago

    Hi,
    could you tell me why the renamed folder shows hour from metadata with 2 hours less than the real hour?
    In the Exif data from my photos (macOS Big Sur) it shows: “Date Time Original: 17 Oct 2020 at 18:56:49”, and more below: “Time Zone for Original Date: +02:00″. If I run your script it shows in the renamed folder name with 16:56:49”.

    Thanks for answers/solutions.

    Kind regards

    Victor

    1 month ago

    Victor: I suppose because it is adjusting for time zone. Add 2 hours if you like.

    Rami
    3 days ago

    Hi – The challenge I have is, when I run the command (mdls) for my photo the result are:

    kMDItemContentCreationDate = 2017-11-02 20:07:18 +0000
    kMDItemContentModificationDate = 2018-12-17 21:07:18 +0000

    (kMDItemContentCreationDate) is not accurate, the (kMDItemContentModificationDate) is the accurate one.
    How I can update the file created date to match (kMDItemContentModificationDate) instated of (kMDItemContentCreationDate) ?

    Thanks for supporting

    2 days ago

    Rami: Did you try just changing the code to use the property you want?

    Rami
    2 days ago

    Yes, Here is the code I used,
    for f in “$@”
    do
    touch -t $(date -j -f “%Y%m%d%H%M” -v-8H $(mdls $f | grep kMDItemContentModificationDate | head -n1 | awk ‘{gsub(“[^[:digit:]]+”,” “);print $1$2$3$4$5}’) +%Y%m%d%H%M
    202105271859) $f
    done

    However, the code above changed the “file modification date” not the “creation date” any thoughts?
    Also, any thoughts on why the kMDItemContentCreationDate does not match kMDItemContentModificationDate?

    2 days ago

    Rami: Not sure why it isn’t working for you. Just keep researching and debugging. I don’t have any more advice off the top of my head right now on this.

Leave a New Comment Related to "How To Change File Creation Dates To Match Photo Metadata"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)