Setting EXIF date from filenames with incomplete dates

Started by jimnastics, October 31, 2024, 05:25:04 AM

Previous topic - Next topic

jimnastics

Hi all,

I've recently scanned in a large set of photos from our family collection. I'd like to get EXIF date data in the files to the best of my ability using the "alldates" flag, however there are going to be many photos where I can only really guess the year, no idea of month let alone day (or obviously time!). I will be going through all the photos and manually renaming them to include my best stab at dates, so I'd appreciate some advise on how best to handle this.

Some I'll be able to do YYYYMMDD, if I set a file to be say "19840511 - 001.jpg", can I just pull the YYYYMMDD from the filename, and get EXIFTOOL to just set 00:00:00 for the time automatically without me having to put that in every filename?

How best to rename and deal with photos where I only know the year, or year and month?

Any help gratefully received, I don't want to manually rename thousands of files and realise I've done it wrong, or could have done it a better way!!

Phil Harvey

While it is technically possible to write partial dates to EXIF (eg. "2024:  :     :  :  "), I don't think support for this is very widespread.  Instead, personally I would put them all on Jan 1 (eg. "2024:01:01 00:00:00").

Partial dates in XMP may be better supported in XMP.  So for these you could also write something like "-XMP:CreateDate=2024".  See FAQ 5 for more information.

- 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 ($).

jimnastics

Quote from: Phil Harvey on October 31, 2024, 07:12:37 AMWhile it is technically possible to write partial dates to EXIF (eg. "2024:  :     :  :  "), I don't think support for this is very widespread.  Instead, personally I would put them all on Jan 1 (eg. "2024:01:01 00:00:00").

Partial dates in XMP may be better supported in XMP.  So for these you could also write something like "-XMP:CreateDate=2024".  See FAQ 5 for more information.

- Phil

OK great, thanks Phil. So do you suggest putting the 00:00:00 in every single filemame for the time, or can EXIFTOOL automate that part with a flag?

Phil Harvey

I wouldn't put it in the file name.  Just add it when copying to a date/time tag. 

- 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

I had to dig it up, but I knew I had done something like this for filenames that only had the year. Original post

Some changes would have to be made because your filenames don't have any separators. Test this first on three files that only has Year, YearMonth, and YearMonthDay filenames. If you're using Windows CMD, change the single quotes into double quotes and vice versa.
exiftool '-AllDates<${Basename;m/(\d{4})(\d\d)?(\d\d)?/;$_=$1.($2//"01").($3//"01")} 00:00:00' /path/to/files/

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

jimnastics

Quote from: StarGeek on October 31, 2024, 10:38:07 AMI had to dig it up, but I knew I had done something like this for filenames that only had the year. Original post

Some changes would have to be made because your filenames don't have any separators. Test this first on three files that only has Year, YearMonth, and YearMonthDay filenames. If you're using Windows CMD, change the single quotes into double quotes and vice versa.
exiftool '-AllDates<${Basename;m/(\d{4})(\d\d)?(\d\d)?/;$_=$1.($2//"01").($3//"01")} 00:00:00' /path/to/files/



Fantastic, thanks, I'll give this a go and report back!

Phil Harvey

#6
I think the "//"s in the expression are meant to be "||"

- Phil

Edit:  Ah. "//" does work.  It's an operator I never use because it was introduced in Perl 5.10 but I want ExifTool to be compatible back to Perl 5.004.  Either operator will work in this case.

- 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

To quote you from that thread
Quote from: Phil Harvey on November 07, 2022, 11:50:15 AMThat's cool.  I've never used the "//" (logical defined-or) operator.  Looking into this, it was added in Perl 5.10.0.

I think I originally found that on one of the Stack Exchange sites without fully understanding it.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

...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 ($).