ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: camner on October 14, 2024, 12:01:09 AM

Title: -if condition based on only hours and minutes of timestamp (ignoring seconds)
Post by: camner on October 14, 2024, 12:01:09 AM
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.
Title: Re: -if condition based on only hours and minutes of timestamp (ignoring seconds)
Post by: StarGeek on October 14, 2024, 01:01:58 AM
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 (https://exiftool.org//exiftool_pod.html#Helper-functions) (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 (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) 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).