Author Topic: Date formatting  (Read 3130 times)

James Penner

  • Jr. Member
  • **
  • Posts: 24
Date formatting
« on: July 16, 2014, 08:57:39 PM »
Hello,

I'm trying to add the current date and some text to the Title field in a pdf. I've got no problem doing that, but the date appears like 20140716. Is there a way to format the date so it takes the form: Wednesday,  July 16, 2014?

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1140
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: Date formatting
« Reply #1 on: July 17, 2014, 03:53:47 AM »
Hi James,

To make the dates come out in a specific format, use the -d option. In your case you probably want -d "%A, %B %e, %Y"

To add some text and the create datetime of the file in the title of the file, you can now use the following:
Code: [Select]
exiftool -d "%A, %B %e, %Y" "-Title<$Title Some Text – $CreateDate – Some more text" <file>(on a Mac, use single quotes).

Hope this helps,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: Date formatting
« Reply #2 on: July 17, 2014, 07:10:04 AM »
Just one point to add.  You can use the Now tag if you want the current date/time.  So Hayo's command would be:

exiftool -d "%A, %B %e, %Y" "-Title<$Title Some Text – $Now – Some more text" <file>

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

James Penner

  • Jr. Member
  • **
  • Posts: 24
Re: Date formatting
« Reply #3 on: July 17, 2014, 07:25:24 PM »
Thank you Hayo and Phil for your responses.

I tried using the command with a slight modification (removing $Title):

exiftool -d "%A, %B %e, %Y" "-Title<Some Text – $Now – Some more text" *.pdf

And I get:

Code: [Select]
Some Text ? B Y ? Some more text
Any ideas as to why I'd be getting this result?



Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1140
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: Date formatting
« Reply #4 on: July 18, 2014, 04:23:58 AM »
Are you on windows or a Mac? On a mac, you should use single quotes (at least for the second part). On windows the problem may be the endash (–), a unicode charater, I used in my example. It may be that windows does not support those properly (hence the question marks). That doesn't explain the B and Y, but it may be related…

Hayo Baan – Photography
Web: www.hayobaan.nl

James Penner

  • Jr. Member
  • **
  • Posts: 24
Re: Date formatting
« Reply #5 on: July 18, 2014, 11:47:51 AM »
Hi Hayo,

I'm on Windows, and it looks like that's why I was having the issues. Removing the endashes helped. I also used double per cent signs, and that seemed to work.

Now, if I use:

exiftool -d "%%A, %%B %%d, %%Y" "-Title<Some Text $Now Some more text" *.pdf

I get:

Code: [Select]
Some Text Friday, July 18, 2014 Some more text
Thank you very much for your help!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: Date formatting
« Reply #6 on: July 18, 2014, 11:51:50 AM »
You must be running from a .bat file for the double "%" to be necessary.

It is very difficult to give accurate advice without knowing details like this (and your system).

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

James Penner

  • Jr. Member
  • **
  • Posts: 24
Re: Date formatting
« Reply #7 on: July 18, 2014, 02:00:09 PM »
Yes, you're correct Phil, I am running the command through a batch file. Sorry I didn't include that. I'd forgotten it makes a difference. I can appreciate it makes things a lot more difficult without all the information, and I'll try to remember to include everything next time. Thanks again to both of you for your help and patience.