-if condition based on only hours and minutes of timestamp (ignoring seconds)

Started by camner, October 14, 2024, 12:01:09 AM

Previous topic - Next topic

camner

I'd like to execute some ExifTool commands only on files in a directory that have DateTimeOriginal timestamps with the time being 01:17:xx (date unimportant).  The logic would be Execute commands only on images captured between 1:17:00AM and 1:17:59AM.

This should be possible with an -if condition (I would think), but the syntax of this is definitely beyond my grasp of ExifTool at this point.

StarGeek

You could use this, which uses regex to match the hour and minute (the leading space is important)
exiftool -if "$DateTimeOriginal=~/ 01:17:/" <rest of command>

Or you could use Perl's greater/less than string comparisons and the DateFmt helper function (ge→Greater than or equal, lt→Less than but not equal)
exiftool -if "${DateTimeOriginal#;DateFmt('%H:%M:%S')} ge '01:17:00' and ${DateTimeOriginal#;DateFmt('%H:%M:%S')} lt '01:18:00'" <rest of command>

The helper function could be removed by using the -d (-dateFormat) option instead, but that is applied globally and would impact any other date/time operations that may be in the rest of your command. If there are none, then you could use
exiftool -d %H:%M:%S -if "$DateTimeOriginal ge '01:17:00' and $DateTimeOriginal lt '01:18:00'" <rest of command>

These commands are written for Windows CMD. If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation (treating the dollar signs as the start of a command line variable, not an exiftool tag name).
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype