MacOS – stat command not respecting time format options (High Sierra 10.13.6)

darwinhigh sierramacos

My goal is to retrieve the birth time of a file formatted to "2019-07-03" so I'm using the following which yields the following epoch time instead of the specific date format I requested:

$ stat -f "%B" -t "%Y-%m-%d" ~/Pictures/to_backup/IMG_2115.JPEG

I get the same output if I leave out the time formatting entirely:

$ stat -f "%B" ~/Pictures/to_backup/IMG_2115.JPEG

I read through what seemed like the pertinent parts of the strftime and stat (<- this one in particular was a face melter) man pages.

What am I missing?

Best Answer

You need to place a S before B which converts the numerals (seconds since epoch) into string output.

stat -f "%SB" -t "%Y-%m-%d" ~/Pictures/to_backup/IMG_2115.JPEG