Author Topic: -if for date/time  (Read 2710 times)

justmike

  • Jr. Member
  • **
  • Posts: 19
-if for date/time
« on: August 16, 2016, 11:20:26 AM »
Is it possible to use the current date and time in an argument? If I would like to find filed created in the last 24 hours, for example.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: -if for date/time
« Reply #1 on: August 16, 2016, 11:32:09 AM »
Yes (using the Extra "Now" tag), but the trick is adjusting this by 24 hours before the comparison:

exiftool -filename -if "$createdate gt ${now;ShiftTime($_,-24)}" DIR

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

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #2 on: August 16, 2016, 11:44:40 AM »
I received a "bad substitution" error. Regarding the shiftTime... all I want to do is search. Will that actually shift it?
exiftool -filename -if  "$createdate gt ${now;ShiftTime($_,-24)}" DIR >/Testing2.csv

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #3 on: August 16, 2016, 11:47:11 AM »
"bash: $createdate gt ${now;ShiftTime($_,-24)}: bad substitution"

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #4 on: August 16, 2016, 11:53:29 AM »
Sorry—it was a single quote issue. exiftool -filename -if -r '$createdate gt ${now;ShiftTime($_,-24)}' DIR >/DIR/Testing2.csv

Received
Code: [Select]
File not found: $createdate gt ${now;ShiftTime($_,-24)}
Do I need the directory in front of the command in this instance?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: -if for date/time
« Reply #5 on: August 16, 2016, 12:02:55 PM »
The -if condition must come immediately after the -if option.   The -r in your command is now being interpreted as the condition, so it must be moved elsewhere in the command line.  Try this:

exiftool -createdate -r -csv -if '$createdate gt ${now;ShiftTime($_,-24)}' DIR >/DIR/Testing2.csv

Note that I am using the CreateDate tag here, which is the creation date from the EXIF metadata.  I don't know if this is what you had in mind.

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

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #6 on: August 16, 2016, 12:34:02 PM »
I did notice that, and nothing meets the conditions, even when I change the hours to accommodate the time when the original was made. I adjusted the code to use the FileModifyDate, and again, nothing meets the conditions. 

exiftool -FileModifyDate -r -csv -if '$FileModifyDate gt ${now(-24)}' DIR >DIR/Testing2.csv

I get:
Code: [Select]
11 directories scanned
    8 files failed condition
    0 image files read

I know one file meets the conditions, because its create date modify date is: 2016:08:15 13:17:41-05:00

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: -if for date/time
« Reply #7 on: August 16, 2016, 12:39:34 PM »
exiftool -FileModifyDate -r -csv -if '$FileModifyDate gt ${now(-24)}' DIR >DIR/Testing2.csv

You broke your -if condition somehow -- the ShiftTime call is missing.  See my first example.

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

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #8 on: August 16, 2016, 02:44:28 PM »
exiftool -filename -FileModifyDate -r -csv -if '$FileModifyDate gt ${now;ShiftTime($_,-24)}' DIR >DIR/Testing2.csv

Nothing...
Code: [Select]
11 directories scanned
    8 files failed condition
    0 image files read

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: -if for date/time
« Reply #9 on: August 16, 2016, 02:55:22 PM »
What version of ExifTool are you using?  This works for me with the current version.

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

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #10 on: August 16, 2016, 04:33:20 PM »
Version 10.25, now, and it worked... Thank you!

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #11 on: August 17, 2016, 12:41:32 PM »
It works in the example you gave, but when I add other things to it, I get all the items listed, not just the ones modified in the previous 24 hours. In this case, it was over 60,000 images. Only 900 or so were changed, and I wanted to list those, not the others. Do I need to include an -if statement for each of the elements I am trying list? I guess the best way to say it is, I do not want a filepath, etc, if the modify date is not in the last 24... Is that somehow outside of the conditional statement?
exiftool -r -filepath -FileModifyDate  -originaldocumentid -documentid -subject -csv -if'$FileModifyDate gt ${now;ShiftTime($_,-24)}' DIR >DIR/File.csv

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14879
    • ExifTool Home Page
Re: -if for date/time
« Reply #12 on: August 17, 2016, 12:42:37 PM »
You need a space after the -if option.

(watch those details!)

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

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #13 on: August 17, 2016, 02:43:12 PM »
 :o Man I really thought it was going to be more complicated than that... I am running it now—takes about 50 minutes, usually, to go through all the files. I will update—thanks!

justmike

  • Jr. Member
  • **
  • Posts: 19
Re: -if for date/time
« Reply #14 on: August 17, 2016, 04:26:46 PM »
Fantastic—that got it. Thank you very much!!