ExifTool Forum

ExifTool => Newbies => Topic started by: knotguy164 on December 06, 2023, 04:48:24 PM

Title: Set datetime file from non-standard string
Post by: knotguy164 on December 06, 2023, 04:48:24 PM
I have a bunch of PDF files that I am trying to set to FileModifyDate to the PDF:CreateDate using
    exiftool '-FileModifyDate<CreateDate' FILE.pdf

However, in these files the PDF:CreateDate is formatted as
    "%A, %B %d, %Y %I:%M:%S %p"

For example
CreateDate : Tuesday, February 23, 1999 9:02:40 AM

The date/time parser doesn't like this format.  It tries to parse it as "1999-09-02 40:00:00" (which fail on hour=40).  If all these numbers are all within acceptable ranges it will quietly set FileModifyDate to the wrong value.
Is there a way to get exiftool to parse the non-standard date on input and use the parsed value to set a standard value output?
Title: Re: Set datetime file from non-standard string
Post by: StarGeek on December 06, 2023, 06:37:45 PM
Try
exiftool -d '%A, %B %d, %Y %I:%M:%S %p' '-FileModifyDate<CreateDate' FILE.pdf
Title: Re: Set datetime file from non-standard string
Post by: Phil Harvey on December 06, 2023, 09:52:18 PM
This is a tricky one... You need to add -api strictdate=0 to that command, otherwise the print conversion of CreateDate will fail.  (Surprisingly, disabling the conversion with CreateDate# doesn't do the trick because of an implementation detail, but the API option provides a work-around.)

- Phil
Title: Re: Set datetime file from non-standard string
Post by: StarGeek on December 06, 2023, 10:34:16 PM
I didn't test this with a PDF, but it worked when I set Description to that value, which I why I assumed it would work.

C:\>exiftool -P -overwrite_original -all= -FileModifyDate=now -Description="Tuesday, February 23, 1999 9:02:40 AM" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -P -overwrite_original -d "%A, %B %d, %Y %I:%M:%S %p" "-FileModifyDate<Description" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -FileModifyDate y:\!temp\Test4.jpg
[System]        FileModifyDate                  : 1999:02:23 09:02:40-08:00

I can't test it with a PDF because I can't set the CreateDate in a PDF to that value. even with the -n (--printConv) option (https://exiftool.org/exiftool_pod.html#n---printConv).
Title: Re: Set datetime file from non-standard string
Post by: Phil Harvey on December 07, 2023, 07:31:00 AM
Quote from: StarGeek on December 06, 2023, 10:34:16 PMI can't test it with a PDF because I can't set the CreateDate in a PDF to that value. even with the -n (--printConv) option (https://exiftool.org/exiftool_pod.html#n---printConv).

Yes, true.  I had to hack the code to be able to do this.

- Phil
Title: Re: Set datetime file from non-standard string
Post by: knotguy164 on December 07, 2023, 11:59:06 AM
Quote from: Phil Harvey on December 06, 2023, 09:52:18 PMThis is a tricky one... You need to add -api strictdate=0 to that command, otherwise the print conversion of CreateDate will fail.  (Surprisingly, disabling the conversion with CreateDate# doesn't do the trick because of an implementation detail, but the API option provides a work-around.)

- Phil

This worked perfectly! Thanks!
(V12.40)

$ exiftool -v4 -d '%A, %B %d, %Y %I:%M:%S %p' '-FileModifyDate<CreateDate' -api strictdate=0 file.pdf
======== CHAP1.pdf
Setting new values from CHAP1.pdf
Writing File:FileModifyDate
    + FileModifyDate = '919782160'
    1 image files updated

I now see
$ exiftool -fileModifyDate -createDate CHAP1.pdf
File Modification Date/Time    : 1999:02:23 09:02:40-06:00
Create Date                    : Tuesday, February 23, 1999 9:02:40 AM

I love this tool!