News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Setting "Date taken" attribute of JPEG Image, from the File name.

Started by tharindusathis, March 24, 2019, 03:10:41 AM

Previous topic - Next topic

tharindusathis

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

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

tharindusathis

I found this and It worked!


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

I notice I incorrectly listed the command, as I forgot the opening BBcode.  That's now been corrected.

Quote from: tharindusathis on March 24, 2019, 04:21:20 AM
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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).