Formatting time values

Started by Martin Z, April 03, 2023, 11:07:57 PM

Previous topic - Next topic

Martin Z

Hi Phil / Team,

BACKGROUND
As you'll know (or at least AFAIK) by default time values are formatted depending on their value:
  • IF duration < 1 minute: "00.00 seconds"
  • IF duration > 1 minute: "H:MM:SS"

QUERY
I would like to format all times as "HH:MM:SS" and looked into 1-2 ways of doing this, however in my case they don't seem to work and am getting a bit stuck, so wonder if you can help me out please! So far, I've considered...
  • Use -n to disable processing: I am also using -d "%d/%m/%Y %H:%M:%S" and if I include -n to the command it blocks -d from working, so I can't use this option [see: -d -n conflict]
  • ❌ Global change to time formatting: I don't have the link, but remember reading on another post that this was hard-ruled-out a while ago as many people/scripts rely on the current rules (which is understandable)

Are there any other ways of setting/controlling this please?



Appendix:  -d -n conflict
Now, overall I have to say I am big fan of EXIFtool and I do appreciate all the work over the years that has been put into it, so I will let you off for this ;) but that said, I'll confess that I was screaming and cursing your name rather loudly earlier as had spent well over an hour banging my head against a brick wall, trying to figure out why EXIFtool wasn't processing my -d parameter...

EXIFTool.exe -c "%.6f" -d "%d/%m/%Y %H:%M:%S" -n %*
I assumed it was something to do with the parent/wrapping script, or maybe something to do with % being expanded before it reached EXIFtool -- I probably tried 20+ combinations of ", "", %, %%, escaping with ^, delayedexpansion on/off, etc but just could not figure it out!...

  • -d is clearly defined for formatting datetime values
  • -n is advised when you want to turn of 'friendly' formatting for time values (dates aren't mentioned in any of the examples)
  • I just can't figure out what I'm doing wrong and why this isn't working

... Until I happen to read a footnote in one of the FAQs saying "-n option may be used to disable all of the date/time reformatting"... HUH!? ... OK, well that explains why EXIFtool wasn't processing my -d argument!  >:(  (At least this means my coding isn't quite as bad as I thought! ;D ::) )

[With genuine tone] Please can I suggest adding a note to the -n / -d sections of the manual, explaining that -n will override/negate -d if it is included... While I appreciate it may seem somewhat niche, it did genuinely eat up a big chuck of my time just now (plus, hopefully wouldn't hurt to make this clearer and avoid anyone else running foul of the same combination).

StarGeek

From the docs on the -n (--printConv) option
    The print conversion may also be disabled on a per-tag basis by suffixing the tag name with a # character

So you can set disable the printconv on individual tags.  For example, with and without the # shortcut
C:\>exiftool -G1 -a -s -Duration -Duration# Y:\!temp\test_drive.MP4
[Kodak]        Duration                        : 0:00:33
[QuickTime]    Duration                        : 0:00:34
[Kodak]        Duration                        : 33
[QuickTime]    Duration                        : 33.7833333333333

So you could use something like
exiftool -if "$Duration#<60" <rest of command>
* 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).

Martin Z

👍🏼 Awesome, thanks @StarGeek!