Convert Exif date data to Date Month Year

Started by michaelw, February 20, 2021, 01:44:11 PM

Previous topic - Next topic

michaelw

Is it possible to covert the Exif date tags (any of Date/Time, Date/Time Original, or Date/Time Digitised) created by my Canon SLR camera to a Date Month Format.

So what I mean by that is my Camera creates a date/time in the style 09/01/2021 10:23:18  I want to use this data to create a caption with the style of 9th January 2021 @ 10:23 Hrs or 10:23 am.

I am assuming that perhaps using an IPTC data set like Source which I am never likely to use would work, not sure whether that is acceptable or not?

To gain maximum flexibility it would be good to be able to separate the  date and time into different date points so I could use one or the other or both.

Hope this makes sense.

Regards

Michael


StarGeek

Quote from: michaelw on February 20, 2021, 01:44:11 PM
Is it possible to covert the Exif date tags (any of Date/Time, Date/Time Original, or Date/Time Digitised) created by my Canon SLR camera to a Date Month Format.

You can format the date however you would like globally by using the -d (-dateFormat) option or individually by using the DateFmt helper function.  See here for all the format codes.

QuoteSo what I mean by that is my Camera creates a date/time in the style 09/01/2021 10:23:18

Since the standard is YYYY:MM:DD HH:mm:ss, if you're camera is actually saving the date in that format, it is doing so in error and would be a problem.  It seems unlikely that a Canon camera would do so.  Make sure you double check with exiftool using this command. 
exiftool -time:all -g1 -a -s file.jpg
Odds are whatever other program you are using to view the date is reformatting it for you.

QuoteI want to use this data to create a caption with the style of 9th January 2021 @ 10:23 Hrs or 10:23 am.

The "1st/2nd/3rd/4-9th" part would be a problem and might have to be changed in a second command.  Also, the date would have a leading zero for days 1-9, though depending upon how it is used, that can probably be changed inline.  Otherwise, the date format string would be
-d "%d %B  %Y @ %H:%m Hrs or %I:%m %p"

Example output
C:\>exiftool -g1 -a -s -DateTimeOriginal -d "%d %B %Y @ %H:%m Hrs or %I:%m %p" y:\!temp\Test4.jpg
---- ExifIFD ----
DateTimeOriginal                : 09 January 2021 @ 14:01 Hrs or 02:01 PM


QuoteI am assuming that perhaps using an IPTC data set like Source which I am never likely to use would work, not sure whether that is acceptable or not?

I don't understand what you're asking here.
* 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).

michaelw

Stargeek,
First of all thank you for your reply.

You are of course correct regarding the Canon camera date format, when I look at an image file straight from the camera using the command you suggested and also Irfanview the date format is  YYYY:MM:DD HH:mm:ss.  I think that the files I looked at had been modified by another program.

I think that the command you so kindly suggested exiftool -g1 -a -s -DateTimeOriginal -d "%d %B %Y @ %H:%m Hrs or %I:%m %p" y:\!temp\Test4.jpg displays the date in the format I want.

I assume by selecting part of the command either side of the "or" would give either the time in 24 hr format of AM or PM?

What I mean by  "I am assuming that perhaps using an IPTC data set like Source which I am never likely to use would work, not sure whether that is acceptable or not"  is as follows.

I would like to run the command on a folder full of files and have the "new date"   09 January 2021 @ 14:01 Hrs  or 09 January 2021 @ 02:01 pm saved in one of the IPTC data elements preferably the date in one and the time in another.

I am unsure which of the elements it would be preferable to use, or even if IPTC elements are the correct way to go?

What I them want to do, at a later date, is in my Image Software (currently ACDSee Ultimate 2021) use this data as part of the creation of a caption.  The reason for having the date and time separate is so I can use one or other or both as needs dictate.

I hope this makes sense and again thank you for your help.

Regards

Michael


StarGeek

Quote from: michaelw on February 21, 2021, 07:07:20 AM
I assume by selecting part of the command either side of the "or" would give either the time in 24 hr format of AM or PM?

Yes, you can edit it how you would like. The percent codes are listed in the link above.

QuoteWhat I mean by  "I am assuming that perhaps using an IPTC data set like Source which I am never likely to use would work, not sure whether that is acceptable or not"  is as follows.

Ah, so you wish to re-purpose a tag for your own use as there isn't an existing tag that fits your needs.

It's your data, so you can do with it what you want (one of my main rules).  I would suggest that you find an XMP tag rather than an IPTC tag, though, as those are more flexible and future proof. The IPTC tags are IPTC IIM/Legacy and are the older standard.  They also have character length limits according to the spec, though nearly all programs ignore that part of the spec.  IPTC Core, which is what the better programs will display, is XMP.

I'd suggest looking through the ACDSee metadata interface and writing something you don't use there to a test file.  Then you can use exiftool to see what tag ACDSee wrote.
* 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).

michaelw

StarGeek,

thank you very much for your reply

First of all I need to re-iterate that I am a very novice user of both Exiftool and ACDSee

I can see no way in ACDSee to view XMP tags or use XMP tags to create captions.  Hence my reason for considering using IPTC elements.

There well may be an IPTC elements that are available to be in ACDSee that I would never use.

For example under Status there are 4 elements: Job Identifier, Instructions, Source and Credit Line that I would never use.

So that being the case could I place the  new date 09 January 2021 in Job Identifier, one of the time elements  @ 14:01 Hrs in Instructions the other time element @ 02:01 pm in say Source.  So that I could use then within the "constraints" of what appears to be visible in ACDSee.

What is the Exiftool code to achieve each of these in a folder of files, I assume that separate commands would have to be run for each element?
Could they be combined in a batch file?

Again I know that my level of knowledge is very low and I apologise for asking perhaps what are very basic questions.

Regards

Michael

StarGeek

Quote from: michaelw on February 21, 2021, 01:45:27 PMI can see no way in ACDSee to view XMP tags or use XMP tags to create captions.  Hence my reason for considering using IPTC elements.
<...>
For example under Status there are 4 elements: Job Identifier, Instructions, Source and Credit Line that I would never use.

These are almost certainly writing to the XMP tag, probably to IPTC IIM/Legacy as well.  Programs such as ACDSee try to provide an easier to understand interface between you and the complex details of the actual metadata.  For example, Job Identifier is probably writing to XMP:TransmissionReference and IPTC:OriginalTransmissionReference, with the latter having a limit of 32 characters, which ACDSee will probably not enforce, but exiftool will unless the -m (-ignoreMinorErrors) option is included in the command.

QuoteWhat is the Exiftool code to achieve each of these in a folder of files, I assume that separate commands would have to be run for each element?

This is where you have to test out what ACDSee actually writes, as I mentioned above.  I do not have ACDSee so I cannot tell you what tags to write to.  Pick one of the tags.  Write the data to a test file.  Run exiftool -g1 -a -s testfile.jpg on that file to see where ACDSee wrote the data.

You can set multiple tags in the same command once you figure out what tags you want to write to.
* 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).

michaelw

StarGeek,

OK I think I might be getting there!:

So I renamed one of my .jpg files to testfile.jpg

I then entered the following into IPTC metadata using ACDSee:

IPTC:Status: Job Identifier   21st February 2021

IPTC:Status: Instructions      21:50 Hrs

IPTC:Status: Source              09:51 PM  (different time deliberately)


I then ran the exif command you gave me exiftool -g1 -a -s testfile.jpg on that file.

I did not know how to direct the output to a file so I have attached a screenshot of the relevant part of the output.

You will see that the data appears in 2 separate places:

---- XMP-photoshop ----
Instructions                    : 21:50 Hrs
TransmissionReference    : 21st February 2021
Source                          : 09:51 PM

and

---- IPTC ----
CodedCharacterSet               : UTF8
Source                          : 09:51 PM
OriginalTransmissionReference   : 21st February 2021
SpecialInstructions             : 21:50 Hrs

I could not see it anywhere else.

So I am assuming that anything written to either of those elements will appear in the 3 IPTC Status Elements in ACDSee?

From what you said earlier I am probably better to use the ---- XMP-photoshop ---- elements ?

But how do I do that!

Again thanks for you help and also your patience

Regards

Michael

StarGeek

Quote from: michaelw on February 21, 2021, 05:20:56 PM
So I am assuming that anything written to either of those elements will appear in the 3 IPTC Status Elements in ACDSee?

Most likely.

QuoteFrom what you said earlier I am probably better to use the ---- XMP-photoshop ---- elements ?

Use XMP:Instructions, XMP:TransmissionReference, and XMP:Source.  If you wanted to use the IPTC IIM/Legacy, you would prefix the listed tags with IPTC:
* 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).

michaelw

StarGeek,
thank you for your reply.

Could you suggest some suitable command line code.

Regards

Michael

StarGeek

exiftool -d "%d %B %Y @ %H:%m Hrs" "-XMP:Instructions<DateTimeOriginal" /path/to/files/
* 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).

michaelw

StarGeek,
thank you very much, I had experimented with the code but had the parameters the wrong way around.

I have noticed something strange with the original command you gave me exiftool -g1 -a -s -DateTimeOriginal -d "%d %B %Y @ %H:%m Hrs or %I:%m %p" y:\!temp\Test4.jpg

I have a file downloaded straight from my camera this morning IMG_9491.jpg which according to Irfanview was taken at 11:18:40.  This is confirmed by Exiftool as shown below

D:\Test>exiftool -g1 -a -s -DateTimeOriginal "IMG_9491.jpg"
---- ExifIFD ----
DateTimeOriginal                : 2021:02:23 11:18:40


The results if I run the original Exiftool command above are shown below:

D:\Test>exiftool -g1 -a -s -DateTimeOriginal -d "%d %B %Y @ %H:%m Hrs or %I:%m %p" "IMG_9491.jpg"
---- ExifIFD ----
DateTimeOriginal                : 23 February 2021 @ 11:02 Hrs or 11:02 AM


So 16 minutes seems to have been subtracted from the DateTimeOriginal element during the processing, although nothing has actually been changed.

I never noticed this before but it happens, not surprisingly, on all the files I have tried.

It is not always 18 minutes please see below for a file that has had some processing where it is around 5 minutes.

D:\Test>exiftool -g1 -a -s -DateTimeOriginal "2021 - 01 - 16 - Chambery Garden - Snow - 0280.JPG"
---- ExifIFD ----
DateTimeOriginal                : 2021:01:16 09:06:53
---- XMP-exif ----
DateTimeOriginal                : 2021:01:16 09:06:53+00:00

D:\Test>exiftool -g1 -a -s -DateTimeOriginal -d "%d %B %Y @ %H:%m Hrs or %I:%m %p" "2021 - 01 - 16 - Chambery Garden - Snow - 0280.JPG"
---- ExifIFD ----
DateTimeOriginal                : 16 January 2021 @ 09:01 Hrs or 09:01 AM
---- XMP-exif ----
DateTimeOriginal                : 16 January 2021 @ 09:01 Hrs or 09:01 AM



So perhaps it is subtracting a percentage of the minutes on as the higher number of minutes in the first file, 18, get reduced by a larger amount that the 2nd file where the minutes are less at 6.

Your thoughts as always very welcome

Regards

Michael




StarGeek

Ooops, my mistake.  Lowercase m (%m) is the month number.  It should be an upper case m %M

exiftool -g1 -a -s -DateTimeOriginal -d "%d %B %Y @ %H:%M Hrs or %I:%M %p" y:\!temp\Test4.jpg

See all the %codes here.
* 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).

michaelw

StarGeek,
thank you very much for the updated code it works perfectly.

Thanks also for the link to the page containing the codes.  Using this I was able to add seconds to the presented date.  I do some time lapse photography so seconds is useful for that.

I am going going to work on using tags to contain the formatted date data, hopefully, thanks to your assistance, with success.

Again thank you for your help.

Regards

Michael