Author Topic: Altering the date format  (Read 1503 times)

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 4075
Altering the date format
« on: April 24, 2012, 12:06:22 AM »

I'm pre-filling some photos with some generic captions ("(person) at (place) on (date)" type thing) and I like that I can preset the date properly using the date format option.   Currently, I'm using "%B %d, %Y" to get output like "January 16, 2011".  My only problem is when the number of the day is less than 10, it returns a zero padding on the left of the day.  For example, I get "January 06, 2011" instead of my preferred "January 6, 2011".  I could remove it with my own user defined tag if I could get the variable in the proper format to begin with.   Unfortunately, I don't know enough to pull this off.  Any tips on how to get my desired formatting so I can operate on it in a user defined tag, or possibly an even better way to do it?
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Alan Clifford

  • ExifTool Freak
  • *****
  • Posts: 486
    • A selection of Alan Clifford's photographs
Re: Altering the date format
« Reply #1 on: April 24, 2012, 03:48:32 AM »
Try %e instead of %d.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 4075
Re: Altering the date format
« Reply #2 on: April 24, 2012, 04:15:50 AM »
Yep tried that.  By itself, it just returns "%e" back.  Replaced in my original format, I get "January , 2011" with no date at all.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17049
    • ExifTool Home Page
Re: Altering the date format
« Reply #3 on: April 24, 2012, 07:17:57 AM »
This user-defined tag will do it, along with the -d "%B %d, %Y" formatting:

Code: [Select]
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Require => 'DateTimeOriginal',
            ValueConv => '$val=$prt[0]; $val=~s/\b0//; $val',
        },
);
# end


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