How to get the "creation date" of any file?

Started by theprof, August 25, 2024, 10:07:03 AM

Previous topic - Next topic

theprof

The file types I have is: MOV, MP4, AVI, WMV, MPEG, HEIC, JPG, GIF, PNG, PDF, DOCX

I want exiftool to return the actual creation date of each file.

For an example, for MOV and MP4 files, I think the creation date is in "QuickTime:CreateDate" (not sure) so it should return that.

For PDF, I think the creation date is in "PDF:CreateDate" so it should return that.

For JPEG, I think it's in "ExifIFD:DateTimeOriginal".

For where it cannot find any "creation date", it should return the File System creation/last modified date.


Phil Harvey

The creation date for a JPG file should be EXIF:CreateDate.  DateTimeOriginal should be the time the original artwork (not the file) was created.

This command will do most of what you ask (assuming you really want EXIF:CreateDate):

exiftool -createdate FILE

The only problem that remains is when the file doesn't contain CreateDate.

For this, the best way would be to create a user-defined tag that "Desire"s CreateDate and FileCreateDate.  You can do this with a config file like this ("my.config"):

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => {
                0 => 'CreateDate',
                1 => 'FileCreateDate',
            },
            ValueConv => '$val[0] || $val[1]',
        },
    },
);
1;

And this command:

exiftool -config my.config -mydate FILE

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Phil Harvey on August 25, 2024, 02:38:49 PMThe creation date for a JPG file should be EXIF:CreateDate.  DateTimeOriginal should be the time the original artwork (not the file) was created.

I think you have that backwards. EXIF:CreateDate is exiftool's name for the EXIF spec's DateTimeDigitized, which is "Date and time of digital data generation". DateTimeOriginal is "Date and time of original data generation".

(general comment for everyone else)
It's confusing and generally meaningless with today's digital cameras, as they will always be the same. The only time they would be different is when an analog image was scanned into a computer to create the digital file. And nobody cares enough about the difference beyond someone working for the Smithsonian or something similar.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Further comments, in regard to videos, CreateDate will be used for MP4/Mov, but it will be in UTC. I think I've seen DateTimeOriginal in AVIs more often, though that is still uncommon. My previous Nikon would save video as AVI. It used both CreateDate and DateTimeOriginal, but it saved the values in the Nikon MakerNotes. The WMV files created by my sister's old camera saved the time in ASF:CreationDate.

Checking a couple of DOCX files, it looks like CreateDate would be the correct tag.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

theprof

Quote from: Phil Harvey on August 25, 2024, 02:38:49 PMThe creation date for a JPG file should be EXIF:CreateDate.  DateTimeOriginal should be the time the original artwork (not the file) was created.

This command will do most of what you ask (assuming you really want EXIF:CreateDate):

exiftool -createdate FILE

The only problem that remains is when the file doesn't contain CreateDate.

For this, the best way would be to create a user-defined tag that "Desire"s CreateDate and FileCreateDate.  You can do this with a config file like this ("my.config"):

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => {
                0 => 'CreateDate',
                1 => 'FileCreateDate',
            },
            ValueConv => '$val[0] || $val[1]',
        },
    },
);
1;

And this command:

exiftool -config my.config -mydate FILE

- Phil


Thanks for the reply. I don't really know anything about the SPECS for JPEGs, MOVs, MP4s etc.

At the end of the day, I simply want a "creation date" when I point exiftool to any "media" file (videos, images, docx, and pdf). I want to avoid writing complex if then else logic....I just want it to provide me the "best" date possible when the file was "shot/taken/created". If it can't find a best date, it should fallback to the last modified date.

Is there such a "flag/switch" to do this? If not, what is the simplest logic I can write to get this "best" create date?


StarGeek

Quote from: theprof on August 25, 2024, 05:32:30 PMI want to avoid writing complex if then else logic....I just want it to provide me the "best" date possible when the file was "shot/taken/created". If it can't find a best date, it should fallback to the last modified date.

The trouble, there isn't a simple solution. Metadata is not nice and neat. It's a messy hellscape of different standards (see xkcd Standards).

QuoteIs there such a "flag/switch" to do this? If not, what is the simplest logic I can write to get this "best" create date?

No. The best thing would be the config file that Phil posted, but probably with a few more tags to look through.

But then there's the additional problem with MP4/Mov files in that the CreateDate must always exist, so when the time is not set, the value is all 0s, 0000:00:00 00:00:00.

Here are some alterations to Phil's config file. I haven't tested it to make sure it works though
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        #--Cut here[--
        MyDate => {
            Desire => {
                0 => 'CreateDate',
                1 => 'DateTimeOriginal',
                2 => 'CreationDate',
                3 => 'FileCreateDate',
            },
            Groups => { 2 => 'Time' },
            ValueConv => '$val[0]=$val[0] eq "0000:00:00 00:00:00" ? undef : $val[0];$val=$val[0] || $val[1] || $val[2] || $val[3]',
        },
        #--Cut here--
    },
);
1;

If you have a .exiftool_config file (see the example.config file), you can add this by copying what's between the "#--Cut here--" lines and placing it in your .exiftool_config directly under the 'Image::ExifTool::Composite' => {line
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

theprof

Thanks for the replies.

I have this for the config file:

%Image::ExifTool::UserDefined = (
    \'Image::ExifTool::Composite\' => {
        MyDate => {
            Desire => {
                0 => \'Quicktime:CreateDate\',
                1 => \'EXIF:CreateDate\',
                2 => \'EXIF:DateTimeOriginal\',
                3 => \'IPTC:DateCreated +\',
                4 => \'IPTC:TimeCreated\',
                5 => \'XMP-exif:DateTimeOriginal\',
                6 => \'XMP-xmp:CreateDate\',
                7 => \'CreationDate\',
                8 => \'FileCreateDate\',
            },
            Groups => { 2 => \'Time\' },
            ValueConv => \'$val[0]=$val[0] eq "0000:00:00 00:00:00" ? undef : $val[0];$val=$val[0] || $val[1] || $val[2] || $val[3] || $val[4] || $val[5] || $val[6] || $val[7] || $val[8]\',
        },
    },
);

1) Is the above correct to get the "most" accurate (or best possible) create date from a image or video file?


2) Also, there is another problem. How do I convert some of them from UTC? For an example, Quicktime:CreateDate is a UTC date so I need to convert it to EST (my time zone). EXIF:DateTimeOriginal is already EST and I don't need to convert it to UTC.

I could do that in my scripting language but is there an easier way to do this in the config file?

3) Is there a way to indicate which value was used? Ex: Was it the CreateDate or DateTimeOriginal that was used in the "best guess"?

Phil Harvey

I can answer question 2):

Add the -api QuickTimeUTC option to convert QuickTime UTC times to the local system time zone.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Why do you have slashes all over the file. The config isn't going to work with them.

3 => \'IPTC:DateCreated +\',
fails because it is looking for a tag that includes the space and the plus sign.
4 => \'IPTC:TimeCreated\',
fails because that is the time only and doesn't include a date.

There is a Composite tag that will automatically combine these for you. Replace these two lines with DateTimeCreated.

Use just the tag names, don't include the group names. If you use simply CreateDate as shown previously, exiftool will return the value of any CreateDate tag that might exist. So it would return either XMP-xmp:CreateDate, EXIF:CreateDate, or Quicktime:CreateDate, depending upon what it finds in the file.

Quote from: theprof on August 28, 2024, 10:49:45 AM3) Is there a way to indicate which value was used? Ex: Was it the CreateDate or DateTimeOriginal that was used in the "best guess"?

It can be done, there was a recent post about doing this. But it requires more complex code.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

theprof

Quote from: StarGeek on August 28, 2024, 11:21:55 AMWhy do you have slashes all over the file. The config isn't going to work with them.

3 => \'IPTC:DateCreated +\',
fails because it is looking for a tag that includes the space and the plus sign.
4 => \'IPTC:TimeCreated\',
fails because that is the time only and doesn't include a date.

There is a Composite tag that will automatically combine these for you. Replace these two lines with DateTimeCreated.

Use just the tag names, don't include the group names. If you use simply CreateDate as shown previously, exiftool will return the value of any CreateDate tag that might exist. So it would return either XMP-xmp:CreateDate, EXIF:CreateDate, or Quicktime:CreateDate, depending upon what it finds in the file.

Quote from: theprof on August 28, 2024, 10:49:45 AM3) Is there a way to indicate which value was used? Ex: Was it the CreateDate or DateTimeOriginal that was used in the "best guess"?

It can be done, there was a recent post about doing this. But it requires more complex code.

Thank you, this was very helpful.

Quick question, what language is the EXIF config file?

StarGeek

Quote from: theprof on August 29, 2024, 05:56:52 AMQuick question, what language is the EXIF config file?

Everything with exiftool is written in Perl.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).