Hi
As I'm new to the tool, I've searched extensively to try and find the answer but to no avail.
I want to update my mp4 videos with CreateDate metadata.
I'm running latest version of efixtool on windows - version 12.1.3.0
I have a large collection of videos where the filename contains the date, but some have only YYYY or YYYY-MM (most have YYYY-MM-DD).
When I run exiftool with "-CreateDate<filename" *.mp4 it works on all the files that have the full date (file 3 example below), but errors on the incomplete ones (file 1 and file 2).
I have also tried to run with -m to ignore errors, but then all the files that are processed end up with 0 values in the -CreateDate field.
Is there a way to inject values in MM and DD only if they don't exist in the file name, to make the dateformat valid?
Example file names:
2021 - file 1.mp4
2021-01 - file 2.mp4
2021-01-01 file 3.mp4
The problem is that any other numbers in the filename, including the 4 in mp4, are used to create the date. So in your last example of 2021-01-01 file 3.mp4, it sets the first 3 numbers as Year, Month, day, but then takes the 3 as the hour and 4 as the minutes, which probably isn't what you would want.
Assuming that you're using the dash as the separator, you could try this
exiftool "-CreateDate<${Filename;m/((?:\d{4})(?:-\d\d)?(?:-\d\d)?)/;$_=$1} 01 01 00 00 00" file.mp4
The 01 would creep into the Hour and Minute the more complete the date is, so the timestamps would be
2021:01:01 00:00:00 - 2021 - file 1.mp4
2021:01:01 01:00:00 - 2021-01 - file 2.mp4
2021:01:01 01:01:00 - 2021-01-01 file 3.mp4
It would be possible to have an exact default value for each time unit, but it would be a more complex command.
Also take note that the CreateDate in a video is assumed to be in UTC, so any of the above examples would show up in Windows/MacOS Findder as 2020:12:31 if you were in a -2:00 or lower timezone. You can try adding the -api QuickTimeUTC option (https://exiftool.org/ExifTool.html#QuickTimeUTC) to adjust the timezone, assuming the computer is in the same timezone as where the video was shot.
If important to only insert MM and DD, but not times from filename, its long expressions like StarGeek is saying defaults is more complex command.
This ${Tag;changes;} to destroy the times, and make default missing MM==01, DD==05, and HHMMSS==01-30-59
"${Filename; s/.*(\d{4}(-\d\d){2}).*/$1/; s/.*(\d{4}-\d\d)(?!-\d\d).*/$1-05/; s/.*(\d{4})(?!-\d\d).*/$1-01-05/; s/.*(\d{4}(-\d\d){2}).*/$1 01-30-59/}"
Its hard to explain but for testing on the commandline, Im think its better explained, and also you can change the defaults ...
exiftool -p "$filename ${filename;s/.*(\d{4}(-\d\d){2}).*/$1/;s/.*(\d{4}-\d\d)(?!-\d\d).*/$1-05/;s/.*(\d{4})(?!-\d\d).*/$1-01-05/;s/.*(\d{4}(-\d\d){2}).*/$1 01-30-59/}" *.mp4
Then, if to be happy with the dates, it can be like... "-CreateDate<${Filename;changes;}"
Thanks heaps - really appreciate the immediate and detailed solutions provided.
I just completed the update (using StarGeek's method as I got started as soon as it got posted).
The best way to show how much it helped is probably to show the log output:
---
51 directories scanned
1426 image files updated
---
Thanks again to both of you!