Set datetime file from non-standard string

Started by knotguy164, December 06, 2023, 04:48:24 PM

Previous topic - Next topic

knotguy164

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?

StarGeek

Try
exiftool -d '%A, %B %d, %Y %I:%M:%S %p' '-FileModifyDate<CreateDate' FILE.pdf
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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.

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

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

knotguy164

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!