News:

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

Main Menu

Date Arithmetic

Started by peterzz, August 26, 2017, 11:14:27 AM

Previous topic - Next topic

peterzz

Hello Exif people  :)

First, may thanks to Phil for a great tool - as an 'oldie' involved in computers since the early days, it's refreshing to see there is still software which is freely shared and does not require me to upload all my personal information to who knows where before I can use it !!!

I would appreciate some help, or a pointer to documents/examples which explain the date selection possibilities in an 'if' statement.  I have the following situation:
- My family take photos on <Create Date> and some days later email them to me
- I receive the email and usually detach the photos soon after receipt.   This becomes the <FileModifyDate> of the file in my computer which will be, say 3 or 4 days after the <Create date>
- Sometimes I don't detach the file until much later - when I come across them while housekeeping the email folders. For these photos the <FileModifyDate> will be much later than the <Create date>
- I would like to correct the <FileModifyDate> for these files to the <CreateDate> so that they sort correctly in my normal photo viewing programs

Question - how can I code an 'if' selection to list files   IF ( FileModifyDate > CreateDate + 7 days)  ?   I cannot use  IF ( FileModifyDate not =  CreateDate) as there will always be some difference, so I need to find files where these dates are close but not necessarily the same.    I cannot find any examples of the syntax to do the date arithmetic - is this possible ?    In fact, is it possible to do the   ( FileModifyDate not =  CreateDate) logic in an if statement ?

I know that I could just extract all the dates to an external file and write a perl program to find the files, but I note that Phil has said ( in 'common mistake no 3'   :)  ) that "Often users write shell scripts to do some specific batch processing when the exiftool application already has the ability to do this either without scripting or with a greatly simplified script" .  And I also want to learn what I can about Exiftool.

Any guidance would be greatly appreciated

Peter

Phil Harvey

Hi Peter,

You could do something like this:

exiftool -if "Image::ExifTool::GetUnixTime($filemodifydate)-Image::ExifTool::GetUnixTime($filecreatedate)>7*24*3600" "-filemodifydate<filecreatedate" DIR

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

Alan Clifford

Phil has answered your question but was the question the right question?  Shouldn't you be using the data from inside the file, viz. datetimeoriginal?

StarGeek

Alternatively, as long as the timestamps are on or after January 1, 1970:
exiftool -if "${FileModifyDate#;DateFmt('%s')}-${CreateDate#;DateFmt('%s')}>7*24*3600" "-FileModifyDate<CreateDate" DIR

I'm operating under the assumption that CreateDate would be the proper tag to compare, as when a file is saved out of an email, the FileModifyDate and FileCreateDate should be the same.
* 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).

peterzz

Hi  - Many thanks to all for the advice.

I went with StarGeek's suggestion as I am not quite ready to use the direct links into perl libraries - and the suggestion works great  (Once I had swapped the quotes around for my Linux box :-) )

A couple of things which I discovered while experimenting, which may be useful for other readers of this thread.

I could print the reformatted dates to the terminal (so I could see if the commands were working as expected) using the -p  option

exiftool  -p '${FileModifyDate;DateFmt("%s")} ${CreateDate;DateFmt("%s")}   $FileModifyDate    $DateTimeOriginal     $FileName' . -ext jpg

but it took me a while to discover that:
-  I had to enclose all fields I wanted to display inside the quotes -p ' . . all fields must be inside  . . . . '
-  For the other tags not being reformatted but inside the single quotes, I needed to drop the leading - and replace with $

for the logic inside the -if function

-if '${FileModifyDate;DateFmt("%s")}-${CreateDate;DateFmt("%s")}<604800'

the minus sign works as expected,  but I could not find a way to print the resulting difference number to the terminal while testing.  Putting the part of the statement on the left of the < inside the -p ' . . . . . . . '  construct just prints the two reformatted dates with a literal minus sign between them, not the numerical difference as hoped  :-(

I am sure these points are covered in the documentation, but it took me a while to figure out, so maybe it helps someone else

Thank you again

I continue my journey with ExifTool . . .

Peter




Phil Harvey

Hi Peter,

Yes, the -if and -p arguments are very similar.  The difference is that the resulting string is evaluated as a Perl expression with -if, while it is only printed with -p.

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