Author Topic: Exiftool IF statement with difference of 2 dates  (Read 157 times)

xhaloz

  • Newbie
  • *
  • Posts: 8
Exiftool IF statement with difference of 2 dates
« on: March 13, 2019, 11:02:56 AM »
Hello,

I've lost a lot of exif data over the years.  To combat this, I wanted to rename a files date by it's modify date ONLY if that date is less than lets say 12 months of the create date.

This would allow me to get a good general idea of the time frame of the photo. Most of my photos go into a folder with a recent date because of missing data.  So I end up with 20K photos in 1 Jan 2019 folder.

To be clear I just want to rename the files if the modify date is 12 months or older than the create date. I would get better data this way. Maybe then I can triple stack within bash to get the oldest date IF it's 12 months or older.

Thanks!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: Exiftool IF statement with difference of 2 dates
« Reply #1 on: March 13, 2019, 11:12:54 AM »
Do you mean something like this?:

exiftool -if "$filemodifydate ge ${filecreatedate;ShiftTime($_,'1:0:0 0')}" ...

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

xhaloz

  • Newbie
  • *
  • Posts: 8
Re: Exiftool IF statement with difference of 2 dates
« Reply #2 on: March 13, 2019, 12:07:06 PM »
Hey Phil,

Thanks for replying. First I want to say I really really like your software.  I've written guides on it over at reddit as well as multiple recommendations.

That aside, I tried your command and received

$modifydate ge ${createdate;ShiftTime($_,'1:0:0 0')}: bad substitution

Any ideas? I am assuming GE stands for greater than or equal to?

Edit, removed the brackets and seems to work.  I'll report back!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: Exiftool IF statement with difference of 2 dates
« Reply #3 on: March 13, 2019, 12:19:46 PM »
What OS are you using?  You must swap quotes for Mac/Linux.  (see my sig)
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

xhaloz

  • Newbie
  • *
  • Posts: 8
Re: Exiftool IF statement with difference of 2 dates
« Reply #4 on: March 13, 2019, 12:32:41 PM »
I see, I am using Linux.  I swapped the quote and the code runs.

I cannot get it to meet the condition though.  I've tried the following

exiftool -if '$filemodifydate ge $filecreatedate' "file.jpg"
exiftool -if '$filemodifydate le $filecreatedate' "file.jpg"

Is there a list of operators such as GE or LE? 

Edit, got it working with exiftool -if '$modifydate lt $createdate' 'test.jpg'

Is there an ELSE operator?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14438
    • ExifTool Home Page
Re: Exiftool IF statement with difference of 2 dates
« Reply #5 on: March 13, 2019, 12:40:41 PM »
OK.  Linux doesn't have a FileCreateDate.  I didn't know exactly what tags you wanted to use, so I guessed at the filesystem modification and creation times.  You need to swap these for the date/time tags you actually want to check.  Use this command to see what is available:

exiftool -time:all -s -G1 FILE

- Phil

Edit: You can google for a list of Perl operators.  There is no ExifTool -else option.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).