Author Topic: Setting "Date taken" attribute of JPEG Image, from the File name.  (Read 179 times)

tharindusathis

  • Newbie
  • *
  • Posts: 2
I have set of JPEG image files which don't have values in "Date taken" attribute. But the JPEG file has the date of image taken.

E.g.:  my_image_1@11-02-2018_22-21-16.jpg
Here Image taken date is 2018/02/11 and time is 22:21:16.

What I need is to set the "Date taken" attribute of all photos (I need to do it for all photos at once). Is it possible to do with this tool? Can you please explain me the method?

Note: I'm very new to this toll and I appreciate your help to do my work. Thank you.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: Setting "Date taken" attribute of JPEG Image, from the File name.
« Reply #1 on: March 24, 2019, 03:27:24 AM »
Normally, FAQ #5, paragraph 3 would be the answer, but in your case, you have a number in the file name before the date and the date itself isn't in a YearMonthDay sequence.  So some reordering of the numbers will be necessary.

Try this on a test file to see if it works for you
exiftool "-AllDates<${filename;s/.*@(\d\d)-(\d\d)-(\d{4})(.*)/$3 $1 $2 $4/}" FileOrDir

This command will strip away everything up to and including the @ sign, then match and reorder the dates, and then match the rest of the filename.  This should make sure the numbers are in YYYY MM DD HH mm SS order.  Exiftool will ignore any extra characters when assigning the timestamp, as mentioned in FAQ 5.  If any file does not match this pattern, the results will not be correct.

This command will create backup files.  Add the Overwrite_Original option to prevent that.  Add the -r option to recurse into subdirectories.
« Last Edit: March 24, 2019, 12:35:27 PM by StarGeek »
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.

tharindusathis

  • Newbie
  • *
  • Posts: 2
Re: Setting "Date taken" attribute of JPEG Image, from the File name.
« Reply #2 on: March 24, 2019, 04:21:20 AM »
I found this and It worked!

Code: [Select]
exiftool
"-datetimeoriginal<
${filename;$_=substr($_,14,4)}:
${filename;$_=substr($_,11,2)}:
${filename;$_=substr($_,8,2)}:
${filename;$_=substr($_,19,2)}:
${filename;$_=substr($_,22,2)}:
${filename;$_=substr($_,25,2)}
+05:30" photo_1@11-02-2018_22-21-16.jpg"

Note: Here +05:30 for timezone.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: Setting "Date taken" attribute of JPEG Image, from the File name.
« Reply #3 on: March 24, 2019, 12:44:23 PM »
I notice I incorrectly listed the command, as I forgot the opening BBcode.  That's now been corrected.

Note: Here +05:30 for timezone.

Just so you know, the addition of the time zone won't be saved, as that particular tag doesn't hold the time zone.  To place to write the time zone so that it matches up with DateTimeOriginal is OffsetTimeOriginal.
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.