Author Topic: Date format %e not working?  (Read 209 times)

faj2323

  • Newbie
  • *
  • Posts: 6
Date format %e not working?
« on: March 25, 2020, 11:42:45 PM »
Having scanned my collection of 18,000+ (mostly railway-related) slides some years ago, I've decided I'd like to revisit them and insert metadata, thus capturing the captions I originally wrote on those slides.

The files are to be renamed in the format YYMMDD-NNN Short description.JPG, e.g. 720706-001 S307 Lara.jpg . [Here, S307 is the locomotive number.]

After studying a lot of code snippets, I've worked out how to write the first part of the filename to DateTimeOriginal, then write the short description to the Description field. Then I append DateTimeOriginal to Description, using the abbreviated month name (with thanks to the helpful post by demianill on January 31, 2020.)

The command I'm using to achieve this is:
-d "%d %b. %Y." "-Description<${filename;$_=substr($_,11);s/\..*?$//}, $datetimeoriginal" -ext jpg .

which produces a description (using the above example) of:
S307 Lara, 06 Jul. 1972.

I referred to http://man7.org/linux/man-pages/man3/strftime.3.html for the date formats.

Better still, I'd like to drop the leading zero where the day is less than 10. I would then have "S307 Lara, 6 Jul. 1972." The date format code for this is %e .

However, the %e code won't write the date at all - I'm just getting "S307 Lara,"

I've seem to have the syntax basically right (because %d works) - have I missed something?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 4075
Re: Date format %e not working?
« Reply #1 on: March 26, 2020, 01:09:07 AM »
See Common Date Format Codes for the list for exiftool.  If you're on Windows, a few of those don't work.  The date codes are system dependent.  %e may work on linux or mac, but not on Windows.

You can trim the leading zeroes by using this for your DateTimeOriginal
${DateTimeOriginal;s/^0+//}

Or see my old thread for a user-defined tag (which I'm still using to this day). 
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

faj2323

  • Newbie
  • *
  • Posts: 6
Re: Date format %e not working?
« Reply #2 on: March 26, 2020, 06:40:54 AM »
Aha - so that's what it was. I saw a link to the linux page somewhere in the exiftool documentation, and looked at that instead of the exiftool Common Date Format Codes.

That works perfectly -- thanks.

Once I'd more-or-less figured out your code, I took it a step further by doing this:
${DateTimeOriginal;s/^0+//;s/May./May/}

which removes the minor cosmetic issue of having a full stop after "May".

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 4075
Re: Date format %e not working?
« Reply #3 on: March 26, 2020, 11:52:11 AM »
Once I'd more-or-less figured out your code, I took it a step further by doing this:
${DateTimeOriginal;s/^0+//;s/May./May/}

which removes the minor cosmetic issue of having a full stop after "May".

Other options would include

Changing your original command from $_=substr($_,11) to $_=substr($_,10) so you don't grab the dot in the first place.

Using the BaseName tag in the example.config file.

Using regex in the original filename to drop the extension
${filename;s/\.[^.]*$//}

Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.