ExifTool Forum

ExifTool => Newbies => Topic started by: salis500 on July 16, 2021, 10:05:10 PM

Title: Creating datetime from nonstandard filename
Post by: salis500 on July 16, 2021, 10:05:10 PM
I haven't coded in years, so total newb.  My filenames are in the format "Month-Day-Year Hour-Min-Sec AM/PM.jpg".  I have several files that have no DateTimeOriginal.  I know of "-datetimeoriginal<filename" but that doesn't work due to my filename date format and time being in 12 hr format.  I'm just having problems getting the parameters set properly to read the name to create a YYYY:MM:DD H:M:S date.

Also, would it be easy with some sort of if command that could check all the pictures in a folder for presence of a ceratin date, and if not, create it from the name.

Sorry for the newb question, any help would be appreciated.
Title: Re: Creating datetime from nonstandard filename
Post by: Phil Harvey on July 16, 2021, 10:31:19 PM
You could maybe try something like this:

exiftool "-datetimeoriginal<${filename;my @a=/\d+/g;$a[3]+=12 if /PM/ and $a[3]!=12;$a[3]=0 if /AM/ and $a[3]==12;$_=qq(@a[2,0,1,3,4,5])}" DIR

The AM/PM is a pain for 12:00.  Here I have set 12:00 AM to 00:00 (24 hr), and 12:00 PM to 12:00 (24 hr), which I think is correct.

There are other ways to do this using the -d option, but the AM/PM may be a problem there too.

- Phil
Title: Re: Creating datetime from nonstandard filename
Post by: StarGeek on July 17, 2021, 12:41:09 AM
Quote from: Phil Harvey on July 16, 2021, 10:31:19 PM
There are other ways to do this using the -d option, but the AM/PM may be a problem there too.

(https://media1.giphy.com/media/M4iOAkEAPwAnK/200.gif)

C:\>exiftool -P -overwrite_original -d "%m-%d-%Y %I-%M-%S %p.jpg" "-DateTimeOriginal<filename" "Y:\!temp\bbb\07-16-2021 12-00-00 PM.jpg" "Y:\!temp\bbb\07-16-2021 12-00-00 AM.jpg"
    2 image files updated

C:\>exiftool -G1 -a -s -DateTimeOriginal "Y:\!temp\bbb\07-16-2021 12-00-00 PM.jpg" "Y:\!temp\bbb\07-16-2021 12-00-00 AM.jpg"
======== Y:/!temp/bbb/07-16-2021 12-00-00 PM.jpg
[ExifIFD]       DateTimeOriginal                : 2021:07:16 12:00:00
======== Y:/!temp/bbb/07-16-2021 12-00-00 AM.jpg
[ExifIFD]       DateTimeOriginal                : 2021:07:16 00:00:00
    2 image files read


It's only because I was pretty sure I remembered that you did did it this way at some point.
Title: Re: Creating datetime from nonstandard filename
Post by: Phil Harvey on July 17, 2021, 07:02:13 AM
Nice. That's much easier than what I did.

- Phil
Title: Re: Creating datetime from nonstandard filename
Post by: salis500 on August 01, 2021, 10:03:11 AM
That worked, thanks.  I don't like that the filenames are in the am/pm format, but back in the day picasa did that so kept using it that way.  I've been wondering if it'd just be easier to convert them to a standard 24hr format to make things easier in the future.