DateTimeOriginal shift +0:0:1 with invalid current date fails with *.jpg

Started by Chuck L, April 15, 2020, 04:52:43 PM

Previous topic - Next topic

Chuck L

I have a large number (in the hundreds) of very old photos that for some reason have invalid values for DateTimeOriginal--the year and month are good, but the rest is all zeroes. For example:


S:\tmp\exiftool > exiftool -r -ext .jpg -if "index($DateTimeOriginal, ':00 00:00:00') != -1" -p "$directory/$filename has bad date $dateTimeOriginal" .
./MVC-001F.JPG has bad date 1998:08:00 00:00:00
./MVC-002F.JPG has bad date 1998:08:00 00:00:00
./MVC-003F.JPG has bad date 1998:08:00 00:00:00
:


I don't know if this is the fault of the camera (my first-ever digital camera, a Sony model) or of some processing I did in Photoshop (I was dumb at the time and didn't preserve the originals). Lightroom doesn't like these timestamps. It ignores them and uses the file timestamp instead. I wanted to try to fix this, and so I tried fixing it with exiftool's date shift feature. Since I don't know the actual day of the month for most of these photos, I thought I would just try adding 1 day to the stored date, setting them all to the first of the month. I wasn't sure if exiftool would accept the invalid date, but it turns out it does, and it does the addition just fine--sometimes.

If I tell exiftool to fix a single file, it works:


S:\tmp\exiftool > exiftool -DateTimeOriginal+="0:0:1 0:0:0" -if "index($DateTimeOriginal, ':00 00:00:00') != -1" MVC-001F.JPG
    1 image files updated

S:\tmp\exiftool > exiftool -DateTimeOriginal MVC-001F.JPG
Date/Time Original              : 1998:08:01 00:00:00


But because I have a lot of these files, I'd like to let exiftool use wildcard matching to get them all in one invocation. And this is where the problems start. exiftool will succeed at updating the date on one file, but then fail on the rest:


S:\tmp\exiftool > exiftool -DateTimeOriginal+="0:0:1 0:0:0" -r -ext .jpg -if "index($DateTimeOriginal, ':00 00:00:00') != -1" .
Warning: Day '00' out of range 1..31 when shifting DateTimeOriginal - ./MVC-003F.JPG
Warning: Day '00' out of range 1..31 when shifting DateTimeOriginal - ./MVC-004F.JPG
Warning: Day '00' out of range 1..31 when shifting DateTimeOriginal - ./MVC-005F.JPG
:
    1 directories scanned
    1 files failed condition
    1 image files updated
   21 image files unchanged


Note that one file was updated, while the rest failed. Trying again:


S:\tmp\exiftool > exiftool -DateTimeOriginal+="0:0:1 0:0:0" -r -ext .jpg -if "index($DateTimeOriginal, ':00 00:00:00') != -1" .
Warning: Day '00' out of range 1..31 when shifting DateTimeOriginal - ./MVC-004F.JPG
Warning: Day '00' out of range 1..31 when shifting DateTimeOriginal - ./MVC-005F.JPG
Warning: Day '00' out of range 1..31 when shifting DateTimeOriginal - ./MVC-006F.JPG
:
    1 directories scanned
    2 files failed condition
    1 image files updated
   20 image files unchanged


This isn't a huge problem for me--I can and will use a script to run exiftool on one file at a time, but I thought I'd report this behavior in case it's easy to fix.

StarGeek

See this thread.  The date/time routines that exiftool uses don't like invalid dates.  In that thread, it was months.

You'll have to use the solution I posted there, except instead of s/2019:13/2020:01/ use s/1998:08:00/1998:08:01/
"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

Chuck L

Thank you for that. In my case, not all of the dates are the same--some are 1998:08:00, some are 1999:01:00, and so on, so my search and replace will have to be slightly different than what you gave, but it's still doable with a single command.

I'm still confused by why the first file succeeds but the remaining files fail. If the date/time library doesn't like invalid dates, why does it work once? Is some state set up the first time that's then retained for subsequent shifts? Implementation details...

And I apologize for not finding that other post on my own. Didn't search with the right keywords, I guess.

StarGeek

Quote from: Chuck L on April 15, 2020, 06:02:31 PM
I'm still confused by why the first file succeeds but the remaining files fail. If the date/time library doesn't like invalid dates, why does it work once?

No idea.

QuoteAnd I apologize for not finding that other post on my own. Didn't search with the right keywords, I guess.

It took me about 20 minutes to re-find that post and I knew what I was looking for.  No worries.
"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