Author Topic: More than one Date Format  (Read 2224 times)

mrbrahman

  • Jr. Member
  • **
  • Posts: 18
More than one Date Format
« on: May 27, 2018, 10:36:35 AM »
Hi,

Is there someway to specify more than one date format?

For e.g. obtain CreateDate and DateTimeOriginal in one format (YYYY-MM-DD HH:MI:SS), and FileModifyDate in Epoch.

Thank you

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15224
    • ExifTool Home Page
Re: More than one Date Format
« Reply #1 on: May 27, 2018, 02:01:36 PM »
You could have to do something fancy to get a date in the epoch, but this could be done by overriding the Extra:FileModifyDate to disable all conversions with a config file like this:

Code: [Select]
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Extra' => {
        FileModifyDate => { },
    },
);
1;  #end

Then the -d option could be used to format the other date/time tags.

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

mrbrahman

  • Jr. Member
  • **
  • Posts: 18
Re: More than one Date Format
« Reply #2 on: May 27, 2018, 04:16:28 PM »
Thanks for looking into this. I should have posted my code first.

Code: [Select]
$ cat t.pl
use Image::ExifTool qw(:Public);

my $filename = "/home/mrbrahman/Pictures/2018/2018-04-04 Some Event/IMG_20180404_203006.jpg";
my @tags = qw( DateTimeOriginal# CreateDate# FileModifyDate);
my %options = (DateFormat => '%s'); #'%Y-%m-%d %H:%M:%S'

my $info = ImageInfo($filename, \@tags, \%options);

map { print $_." :".$info->{$_}."\n" } keys(%{$info});

$
$ perl t.pl
DateTimeOriginal # :2018:04:04 20:30:06
CreateDate # :2018:04:04 20:30:06
FileModifyDate :1526480310

The FileModifyDate is indeed coming out as Unix Epoch, but the other formats are the POSIX format.

I'd like the other 2 fields to come out in YYYY-MM-DD HH:MI:SS format.

Is that possible?

Thanks.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15224
    • ExifTool Home Page
Re: More than one Date Format
« Reply #3 on: May 28, 2018, 07:31:00 AM »
You have disabled the date formatting with the trailing "#" on the tag names.

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

mrbrahman

  • Jr. Member
  • **
  • Posts: 18
Re: More than one Date Format
« Reply #4 on: May 28, 2018, 09:54:22 AM »
So, here's the output with the # removed and the format is unix epoch on all 3.

Code: [Select]
$ cat t.pl
use Image::ExifTool qw(:Public);

my $filename = "/home/mrbrahman/Pictures/2018/2018-04-04 Some Event/IMG_20180404_203006.jpg";
my @tags = qw( DateTimeOriginal CreateDate FileModifyDate);
my %options = (DateFormat => '%s'); #'%Y-%m-%d %H:%M:%S'

my $info = ImageInfo($filename, \@tags, \%options);

map { print $_.": ".$info->{$_}."\n" } keys(%{$info});


$ perl t.pl
CreateDate: 1522888206
DateTimeOriginal: 1522888206
FileModifyDate: 1526480310

Is it possible to get the YYYY-MM-DD HH:MI:SS format for only the CreateDate and DateTimeOriginal fields?

Thanks


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15224
    • ExifTool Home Page
Re: More than one Date Format
« Reply #5 on: May 28, 2018, 10:03:07 AM »
You can do it with a user-defined tag as I mentioned:

Code: [Select]
$ cat t.pl
use Image::ExifTool qw(:Public);

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Extra' => {
        FileModifyDate => { },
    },
);

my $filename = "a.jpg";
my @tags = qw( DateTimeOriginal CreateDate FileModifyDate);
my %options = (DateFormat => '%Y-%m-%d %H:%M:%S');

my $info = ImageInfo($filename, \@tags, \%options);

map { print $_.": ".$info->{$_}."\n" } keys(%{$info});

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

mrbrahman

  • Jr. Member
  • **
  • Posts: 18
Re: More than one Date Format
« Reply #6 on: May 28, 2018, 08:12:01 PM »
Thanks so much!

mrbrahman

  • Jr. Member
  • **
  • Posts: 18
Re: More than one Date Format
« Reply #7 on: June 02, 2018, 12:39:01 PM »
I tried to implement the same for 2 other fields -- FileSize and Orientation.

FileSize is giving me the proper value (in bytes), bur Orientation is not.

Code: [Select]

$ cat t.pl
use File::Find::Iterator;
use Image::ExifTool qw(:Public);
use Data::Dumper;

sub isfile { -f }

my $find = File::Find::Iterator->create(dir => ["images/"], filter => \&isfile)
              or die "ERROR: Cannot read Directory";

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Extra' => {
        FileModifyDate => { },
        FileSize => { },
        Orientation => { },
    },
);

my %options = (DateFormat => '%Y-%m-%d %H:%M:%S');
my @tags = qw( FileName FileSize Orientation MIMEType Keywords RegionName Rating Make DateTimeOriginal CreateDate FileModifyDate);

while (my $filename = $find->next) {
  my $info = ImageInfo($filename, @tags, \%options);
  print Dumper($info);
}

Code: [Select]
$ perl t.pl
$VAR1 = {
          'CreateDate' => '2017-12-25 20:06:31',
          'FileSize' => 2392267,
          'MIMEType' => 'image/jpeg',
          'Rating' => '5',
          'FileModifyDate' => 1527631893,
          'DateTimeOriginal' => '2017-12-25 20:06:31',
          'RegionName' => 'Brahman',
          'Make' => 'LGE',
          'Keywords' => 'Cousins',
          'FileName' => 'IMG_20171225_200630.jpg',
          'Orientation' => 'Horizontal (normal)'
        };

Anything special needed here?

Thanks!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15224
    • ExifTool Home Page
Re: More than one Date Format
« Reply #8 on: June 03, 2018, 08:09:14 AM »
FileSize is an Extra tag, so this works, but Orientation is an EXIF Tag, so you must override this in the EXIF table.

But I don't think this should be necessary.  Just request Orientation# instead of Orientation.  Same with FileSize actually.  The reason you needed to override FileModifyDate is because the unformatted value was a string format, and you wanted the unix epoch.  But for both FileSize and Orientation the unformatted value is an integer.

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

mrbrahman

  • Jr. Member
  • **
  • Posts: 18
Re: More than one Date Format
« Reply #9 on: June 06, 2018, 04:05:34 PM »
Thank you Phil!