Filename to date/time, with timezone offset

Started by mazeckenrode, October 23, 2024, 01:50:56 PM

Previous topic - Next topic

mazeckenrode

I use the following command line to set date/time tags in PDFs and applicable image files from filenames:

ExifTool -m "-EXIF:DateTimeOriginal<Filename" "-XMP:DateTimeOriginal<Filename" "-PDF:CreateDate<Filename" "-IPTC:DateCreated<${Filename;m/^(\d{4})[-_;\., ]*(\d{2})[-_;\., ]*(\d{2})/;$_=$1.$2.$3}" "-IPTC:TimeCreated<${Filename;m/^\d{4}[-_;\., ]*\d{2}[-_;\., ]*\d{2}[-_;\., ]*(\d{2})[-_;\., ]*(\d{2})[-_;\., ]*(\d{2})/;$_=$1.$2.$3}" {filepath$}
My filenames always contain 14 digits at the beginning to facilitate this operation, and often contain other digits elsewhere as well (partial account number, etc.), but do not contain timezone offsets, and I'd prefer to keep offsets out of them. Is there any way I can have ExifTool detect the timezone offset in use on my computer and apply it as well to all applicable tags when running this command? The offset in use where I live isn't constant — we're currently still on daylight savings here, but that ends in a week or two.

mazeckenrode

Whoops, sorry, used the wrong markup for my command line:

ExifTool -m "-EXIF:DateTimeOriginal<Filename" "-XMP:DateTimeOriginal<Filename" "-PDF:CreateDate<Filename" "-IPTC:DateCreated<${Filename;m/^(\d{4})[-_;\., ]*(\d{2})[-_;\., ]*(\d{2})/;$_=$1.$2.$3}" "-IPTC:TimeCreated<${Filename;m/^\d{4}[-_;\., ]*\d{2}[-_;\., ]*\d{2}[-_;\., ]*(\d{2})[-_;\., ]*(\d{2})[-_;\., ]*(\d{2})/;$_=$1.$2.$3}" {filepath$}

Phil Harvey

ExifTool automatically assumes your system time zone if one is required but not specified.  So the only thing you have to do is remove any unnecessary numbers from the file name.  You seem to be attempting to reformat the filename as a proper date/time string, but this shouldn't be necessary (read the paragraph beginning with "Having said this" in FAQ 5).

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

Phil Harvey

I realize now what you need wrt the time zone.

I would do this as a 2-step process:

1. Set FileModifyDate from the file name.  The system time zone will be assumed.

2. Copy FileModifyDate directly to the other tags (including IPTC:TimeCreated without reformatting).  The time zone will get written if valid for the tag.  Add -P to the command to preserve FileModifyDate if you want.

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

mazeckenrode

Quote from: Phil Harvey on October 23, 2024, 02:16:15 PMSo the only thing you have to do is remove any unnecessary numbers from the file name.

There are no unnecessary numbers. Everything is there because I want it there.

QuoteYou seem to be attempting to reformat the filename as a proper date/time string, but this shouldn't be necessary (read the paragraph beginning with "Having said this" in FAQ 5).

Not sure offhand if anything relevant to that with ExifTool has changed since 23 Jun 2020, but that command line was worked out mostly with StarGeek's help in a forum topic I started, beginning with this post.

Quote from: Phil Harvey on October 23, 2024, 02:33:09 PMI realize now what you need wrt the time zone.

Thanks, though I assume it won't work unless I remove the other numbers from the filenames, right?

Phil Harvey

I don't think anything significant changed since 2020.  IPTC:TimeCreated is a problem because you do need to strip off the date if writing to that tag with a date+time not separated by a space.

Writing the file name directly to FileModifyDate will require that you strip off any numbers after the seconds to use the 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 ($).

mazeckenrode

Quote from: Phil Harvey on October 23, 2024, 03:26:07 PMIPTC:TimeCreated is a problem because you do need to strip off the date if writing to that tag with a date+time not separated by a space.

For what it's worth, my dates & times in filenames are formatted as XXXX-XX-XX XX;XX;XX — there IS a space. But it doesn't work for writing IPTC:TimeCreated (at least, it didn't for me back in 2020).

Phil Harvey

Yeah, the semicolons wouldn't work.  It has to be either colons or nothing.  This works (single quotes for me because I'm on Mac):

> exiftool '-iptc:timecreated<${filename;tr/;/:/}' '-iptc:datecreated<filename' -v3 "2024-10-23 01;02;03.jpg"
======== 2024-10-23 01;02;03.jpg
Setting new values from 2024-10-23 01;02;03.jpg
Writing IPTC:TimeCreated
Writing IPTC:DateCreated
Rewriting 2024-10-23 01;02;03.jpg...
  Editing tags in: APP13 IPTC Photoshop
  Creating tags in: APP13 IPTC Photoshop
Creating APP13:
  Creating Photoshop
  Creating IPTC
    + IPTC:DateCreated = '20241023'
    + IPTC:TimeCreated = '010203-0400'
    + IPTC:ApplicationRecordVersion = '4' (mandatory)
JPEG DQT (130 bytes)
JPEG SOF0:
JPEG DHT (73 bytes)
JPEG SOS
    1 image files updated

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