ExifTool Forum

ExifTool => Archives => Topic started by: Archive on May 12, 2010, 08:53:55 AM

Title: Problem transferring dates from DatetimeOriginal to FileModifyDate
Post by: Archive on May 12, 2010, 08:53:55 AM
[Originally posted by parz on 2006-08-07 01:03:35-07]

I am having some problems with the DatetimeOriginal key values using exiftool. I don't know if these problems are bugs or features, or I am just ignorant as to how the program works.

I am trying to transfer a date to the FileModifyDate as in

Code:
[parz@lobsang exif]$ exiftool "-DatetimeOriginal>FileModifyDate" Cape-Merry-photogs.jpg
    0 image files updated
    1 image files unchanged

exiftool will not transfer the date. The date was put into the the file by exiftool, but the year was specified with slashes, and so recorded. The program will transfer the date to say "CreationTime", but not to "FileModifyDate".

Code:
[parz@lobsang exif]$ exiftool -s -DatetimeOriginal Cape-Merry-photogs.jpg
DateTimeOriginal                : 1984/07/03 23:00:00

I have found that if I try this on a file where the DatetimeModified key date is specified with colons, exiftool will transfer the date to FileModifyDate. I have also found that exiftool will understands the slash separated date format, because it will increment such a date, by say 1 year.
When it does increment the date, the incremented date is also stored with the date components separated by slashes.

I understand that the correct format for DatetimeOriginal dates has the date components separated by colons, not slashes. So now I have the following questions:

1) I had expected that exiftool would either not accept, or else correctly parse and store a date in the DatetimeOriginal key. So if the date was specified with slashes, but that key required colons, exiftool would not store an incorrectly formatted date. Is this a bug in exiftool?

2) If a slash separated date is incorrect, it seems that exiftool and other programs I use are happy with the date in this format, and parse and use it. So why does exiftool refuse to move this value to the FileModifyDate key, but it will move a colon separated date?

3) Not knowing any better, I have now over a thousand scanned images into which I have added a DatetimeOriginal which has the slash separator in the date portion. Is there some relatively simple way to correct these values, assuming that they are in error. In particular I want them corrected because then I can use exiftool to transfer these dates to the file dtm on some files, especially my PNG files, where some other programs (in particular KPhotoalbum) do not recognize exif data, and date those files using the file dtm.

I would like some help understanding and solving these problems.

Thanks, Parzival
Title: Re: Problem transferring dates from DatetimeOriginal to FileModifyDate
Post by: Archive on May 12, 2010, 08:53:56 AM
[Originally posted by exiftool on 2006-08-22 12:21:50-07]

Hi Parzival, I will try to answer your questions:

1) For date/times stored as strings, ExifTool does not currently validate the format of the string when writing.  This is something I may add in the future.

2) It looks like I have been inconsistent in my parsing of date/time values.  I will look into this and try to make this more consistent.

3) It is a relatively simple matter to write a script to fix the date syntax:

Code:
#!/usr/bin/perl -w
use strict;
BEGIN { push @INC, 'lib' }
use Image::ExifTool;
my $exifTool = new Image::ExifTool;

for (;;) {
    my $file = shift or last;
    my $info = $exifTool->ImageInfo($file);
    $$info{Error} and warn("Error: $$info{Error}\n"), next;
    $$info{Warning} and warn("Warning: $$info{Warning}\n");
    $exifTool->SetNewValue();
    print "File: $file\n";
    foreach (qw(DateTimeOriginal CreateDate ModifyDate)) {
        my $date = $$info{$_};
        next unless $date and $date =~ s/\//:/g;
        $exifTool->SetNewValue($_, $date);
        print "  Updating $_\n";
    }
    unless ($exifTool->CountNewValues()) {
        print "  Nothing to do\n";
        next;
    }
    my $result = $exifTool->WriteInfo($file);
    if ($result == 1) {
        print "  Done.\n";
    } elsif ($result == 2) {
        print "  Nothing changed.\n";
    } else {
        print "  Write Error!\n";
    }
}
# end

Place this script in the same directory as "exiftool".  It takes one or more file names as arguments and will convert slashes to colons in DateTimeOriginal, CreateDate and ModifyDate.