ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Tezlacore on April 16, 2023, 10:49:10 AM

Title: Timestamping / timezoning in windows explorer
Post by: Tezlacore on April 16, 2023, 10:49:10 AM
Hi all! I've been playing around with Exiftool for a while now and have managed to do everything I needed to do without asking for help - until now.

Short background: I'm dealing with the whole Google Takeout issue of files (seemingly) missing metadata (GPS data, timestamps).

I found out (from more recent photo files, directly downloaded from my iPhone) that the following metadata timestamps should be included on a photo file, in the format stated (whereby "NL" is The Netherlands, the country I'm residing, and "local" is the location in which the photo was taken):
• System:FileCreateDate --> NL time at the time of recording + timezone indication of NL (yyyy:mm:dd hh:mm:ss+HH:MM)
• System:FileModifyDate --> NL time at the time of recording + timezone indication of NL (yyyy:mm:dd hh:mm:ss+HH:MM)
• IFD0:ModifyDate --> local time (yyyy:mm:dd hh:mm:ss)
• ExifIFD:DateTimeOriginal -->  local time (yyyy:mm:dd hh:mm:ss)
• ExifIFD:CreateDate --> local time (yyyy:mm:dd hh:mm:ss)
• ExifIFD:OffsetTime --> timezone indication of local country (eg "+03:00" or "Z")
• ExifIFD:OffsetOriginal --> timezone indication of local country (eg "+03:00" or "Z")
• ExifIFD:OffsetDigitized --> timezone indication of local country (eg "+03:00" or "Z")
• GPS:GPSDateStamp --> datestamp only (eg yyyy:mm:dd)
• XMP-xmp:CreateDate --> local time (yyyy:mm:dd hh:mm:ss)
• XMP-xmp:ModifyDate --> local time (yyyy:mm:dd hh:mm:ss)
• XMP-photoshop:DateCreated --> local time (yyyy:mm:dd hh:mm:ss)
• Composite:SubSecCreateDate --> local time + timezone indication of local country (yyyy:mm:dd hh:mm:ss+HH:MM)
• Composite:SubSecDateTimeOriginal --> local time + timezone indication of local country (yyyy:mm:dd hh:mm:ss+HH:MM)

To get these set on each photo file in the target folder, I'm running the following script (whereby "$timezone" is the local timezone in which the photo was shot):

$targetfolder = "C:\photofolder"
$timezone = "+07:00"
C:\exiftool.exe -ExifIFD:OffsetTime="$timezone" -ExifIFD:OffsetTimeOriginal="$timezone" -ExifIFD:OffsetTimeDigitized="$timezone" '-XMP-xmp:CreateDate<ExifIFD:DateTimeOriginal' '-XMP-xmp:ModifyDate<ExifIFD:DateTimeOriginal' '-XMP-photoshop:DateCreated<ExifIFD:DateTimeOriginal' '-IFD0:ModifyDate<ExifIFD:DateTimeOriginal' '-Composite:SubSecCreateDate<$ExifIFD:DateTimeOriginal"'$timezone'"' '-Composite:SubSecDateTimeOriginal<$ExifIFD:DateTimeOriginal"'$timezone'"' '-FileCreateDate<$XMP-exif:GPSDateTime +00:00' '-FileModifyDate<$XMP-exif:GPSDateTime +00:00' -common_args -overwrite_original_in_place -ext JPG -ext HEIC -ext PNG --ext AAE --ext JSON -overwrite_original -progress $targetfolder

The result (I think) is as desired in Exiftool (see screenshot attached). However, the files are still showing the local timezone timestamps in Windows Explorer (see second screenshot) which makes that sorting by Date doesn't work as desired.

I think (maybe) the trick is to first get rid of ALL timestamp information on the file (by running a '-AllDates=' for example) and then rewriting the metadata timestamps I want back to the file. However, if I delete all timestamp information first, I've got nothing to write back to the file anymore.

I could do this with a for/while loop, first calling exiftool to write the timestamp info to temporary variables, then calling exiftool again to delete all timestamp metadata on the file and then writing the desired timestamp metadata back to the file using the timestamps stored in the temporary variables, but I have a feeling there should be an easier way...

Any help is greatly appreciated!
Title: Re: Timestamping / timezoning in windows explorer
Post by: StarGeek on April 16, 2023, 12:45:36 PM
Quote from: Tezlacore on April 16, 2023, 10:49:10 AMShort background: I'm dealing with the whole Google Takeout issue of files (seemingly) missing metadata (GPS data, timestamps).

Google doesn't remove any data from the files.  The only thing lost was the file system time stamps.  Any embedded data is still there and if you copy data from the json files, you are overwriting the data that is already in the file.  And because the time stamps in the json file are UTC, you are writing the incorrect date/time.

The only time you should try to copy data from the json files is when you edited the data on the Google website. 

Quote• IFD0:ModifyDate --> local time (yyyy:mm:dd hh:mm:ss)
• ExifIFD:DateTimeOriginal -->  local time (yyyy:mm:dd hh:mm:ss)
• ExifIFD:CreateDate --> local time (yyyy:mm:dd hh:mm:ss)
• ExifIFD:OffsetTime --> timezone indication of local country (eg "+03:00" or "Z")
• ExifIFD:OffsetOriginal --> timezone indication of local country (eg "+03:00" or "Z")
• ExifIFD:OffsetDigitized --> timezone indication of local country (eg "+03:00" or "Z")

My suggestion here is not to worry about the subgroups.  All of these can be set by just using the name of the tag, such as -DateTimeOriginal="2023:04:16 12:00:00" or if you need to be specific, use -EXIF:DateTimeOriginal="2023:04:16 12:00:00".  Using the subgroups, especially in the case of the EXIF ones where the subgroup names are not very clear, is just unneeded extra work and makes it more likely to write to the wrong spot.  Exiftool knows the best location for these, let it do the work for you.

Quote• GPS:GPSDateStamp --> datestamp only (eg yyyy:mm:dd)

There is also the GPSTimeStamp which hold the time portion of the GPS date/time.  Additionally, there is the XMP:GPSDateTime, which holds both the date and time.  It does not have to be set to UTC but if it isn't UTC, it needs to include the time zone.

Looking at your command, you use the XMP:GPSDateTime not the ones in the GPS group (which are actually part of the EXIF group)

Quote• XMP-xmp:CreateDate --> local time (yyyy:mm:dd hh:mm:ss)
• XMP-xmp:ModifyDate --> local time (yyyy:mm:dd hh:mm:ss)
• XMP-photoshop:DateCreated --> local time (yyyy:mm:dd hh:mm:ss)

XMP time stamps can also include the time zone.

Quote• Composite:SubSecCreateDate --> local time + timezone indication of local country (yyyy:mm:dd hh:mm:ss+HH:MM)
• Composite:SubSecDateTimeOriginal --> local time + timezone indication of local country (yyyy:mm:dd hh:mm:ss+HH:MM)

Note that these are not embedded tags.  Composite tags are created by exiftool on the fly by combining other tags.  In this case, they combine the EXIF time stamp with the corresponding EXIF time zone and EXIF subsecond tags.  These are writable, allowing you to write all three at once, but not all Composite tags are writable.

Additionally, writing to these tags supersede some of the previous assignments.  See Note #1 under the -TAG[+-^]=[VALUE] option (https://exiftool.org/exiftool_pod.html#TAG---VALUE).

QuoteThe result (I think) is as desired in Exiftool (see screenshot attached). However, the files are still showing the local timezone timestamps in Windows Explorer (see second screenshot) which makes that sorting by Date doesn't work as desired.

The file system time stamps are always local time.  You cannot change this.  And the file system time stamps are fragile and really shouldn't be used for sorting.  The "Date Taken" property for images and the "Media Created" property for videos actually read the date/time embedded in the file.

QuoteI think (maybe) the trick is to first get rid of ALL timestamp information

IMO, this is a bad idea. You introduce the possiblity of errors and you're needlessly overwriting the good data that's already there.

In my opinion, a two step process would be best. You'll have to figure out the exact quoting need for Powershell, but these would be the basic ideas.

First, set the time zones with
exiftool -OffsetTime*=$TimeZone /path/to/files/

Once you do that, the rest becomes simpler, though the XMP:DateCreated (part of the IPTC standard) has to be handled separately, as copying to XMP:AllDates will copy DateTimeOriginal into the XMP:DateTimeOriginal tag (part of the EXIF for XMP standard).  You can now copy the EXIF time stamps directly into the XMP ones with
"-XMP:AllDates<AllDates" "-XMP:DateCreated<DateTimeOriginal"
or if you want to include the time zones and subseconds, you could use
"-XMP:CreateDate<SubSecCreateDate" "-XMP:DateTimeOriginal<SubSecDateTimeOriginal" "-XMP:ModifyDate<SubSecModifyDate" "-XMP:DateCreated<SubSecDateTimeOriginal"

You might also create the EXIF GPS time stamps (the GPS group tags (https://exiftool.org/TagNames/GPS.html)), as these are more likely to be read over the XMP:GPSDateTime
"-GPS*Stamp<SubSecDateTimeOriginal"

In your command, you use
-ext JPG -ext HEIC -ext PNG --ext AAE --ext JSON
You don't need to exclude groups when you are already limiting processing to jpg, heic, and PNG.  This could be simplified to just
-ext JPG -ext HEIC -ext PNG

Your command lists both -overwrite_original_in_place option (https://exiftool.org/exiftool_pod.html#overwrite_original_in_place) and -overwrite_original option (https://exiftool.org/exiftool_pod.html#overwrite_original).  Since you're on Windows, the -overwrite_original_in_place needlessly doubles the processing time.  The only time you would need to use it would be if your had Alternate Data Streams (ADS) attached to your files.  The -overwrite_original_in_place option main use is for Macs, where there are a lot of other tags which are part of the file system and might be otherwise lost.

The -Common_Args option (https://exiftool.org/exiftool_pod.html#common_args) isn't needed here.

Here's my full suggested command.  First the above command to set the time zones
exiftool -OffsetTime*=$TimeZone /path/to/files/

then
exiftool -overwrite_original -Progress -ext JPG -ext HEIC -ext PNG "-FileCreateDate<SubSecDateTimeOriginal" "-FileModifyDate<SubSecDateTimeOriginal" "-GPS*Stamp<SubSecDateTimeOriginal" "-XMP:CreateDate<SubSecCreateDate" "-XMP:DateTimeOriginal<SubSecDateTimeOriginal" "-XMP:ModifyDate<SubSecModifyDate" "-XMP:DateTime<SubSecDateTimeOriginal" /path/to/files/

At least I think I covered everything.
Title: Re: Timestamping / timezoning in windows explorer
Post by: StarGeek on April 16, 2023, 12:51:07 PM
After all that, I realized that you probably had mixed images and videos and wanted them sorted properly.  Unfortunately, video and images end up with separate columns when Windows reads the embedded time stamps
(https://i.imgur.com/GD4Vvhx.png)

So the FileModifyDate will have to do.
Title: Re: Timestamping / timezoning in windows explorer
Post by: Tezlacore on April 16, 2023, 01:56:35 PM
Thanks so much for the quick and very elaborate reply, StarGeek! Some helpful tips in there to finetune the code.

Quote from: StarGeek on April 16, 2023, 12:51:07 PMAfter all that, I realized that you probably had mixed images and videos and wanted them sorted properly.  Unfortunately, video and images end up with separate columns when Windows reads the embedded time stamps
(https://i.imgur.com/GD4Vvhx.png)

So the FileModifyDate will have to do.

I think this pretty much sums up the issue I'm facing and the solution. Probably little or no need to adjust all the files, just sort by the "Date Modified" column in Windows Explorer rather than by the "Date" column and the problem's sorted. Wish life was always this easy.

Btw, I did try your code, but:

Quote from: StarGeek on April 16, 2023, 12:45:36 PMHere's my full suggested command.  First the above command to set the time zones
exiftool -OffsetTime*=$TimeZone /path/to/files/

This gives me a "Warning: Error converting value for ExifIFD:OffsetTimeOriginal (PrintConvInv) Nothing to do." error  :-\ (and yes, I did change the /path/to/file to my actual folder location), and:

Quote from: StarGeek on April 16, 2023, 12:45:36 PMthen
exiftool -overwrite_original -Progress -ext JPG -ext HEIC -ext PNG "-FileCreateDate<SubSecDateTimeOriginal" "-FileModifyDate<SubSecDateTimeOriginal" "-GPS*Stamp<SubSecDateTimeOriginal" "-XMP:CreateDate<SubSecCreateDate" "-XMP:DateTimeOriginal<SubSecDateTimeOriginal" "-XMP:ModifyDate<SubSecModifyDate" "-XMP:DateTime<SubSecDateTimeOriginal" /path/to/files/

this gives me a "Warning: No writable tags set from FILENAME. Nothing changed in FILENAME" error.
Title: Re: Timestamping / timezoning in windows explorer
Post by: StarGeek on April 16, 2023, 02:17:49 PM
For the OffsetTime tags, you'll have to figure out the quoting to make your "$Timezone" variable work correctly.  It works correctly directly on the command line, even in PS
PS C:\> exiftool -P -overwrite_original -offsettime*=-07:00 y:\!temp\Test4.jpg
    1 image files updated
PS C:\> exiftool -G1 -a -s -OffsetTime* y:\!temp\Test4.jpg
[ExifIFD]       OffsetTime                      : -07:00
[ExifIFD]       OffsetTimeOriginal              : -07:00
[ExifIFD]       OffsetTimeDigitized             : -07:00

Powershell isn't the best for exiftool, it has a lot of idiosyncrasies that can break exiftool commands that work in CMD or on Mac/Linux.

Once that works and the OffsetTime is in the file, it should work

Example:
C:\>exiftool -time:all --system:all -G -a -s y:\!temp\Test4.jpg
[EXIF]          ModifyDate                      : 2023:04:16 12:00:00
[EXIF]          DateTimeOriginal                : 2023:04:16 12:00:00
[EXIF]          CreateDate                      : 2023:04:16 12:00:00

C:\>exiftool -P -overwrite_original -offsettime*=-07:00 y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -time:all --system:all -G -a -s y:\!temp\Test4.jpg
[EXIF]          ModifyDate                      : 2023:04:16 12:00:00
[EXIF]          DateTimeOriginal                : 2023:04:16 12:00:00
[EXIF]          CreateDate                      : 2023:04:16 12:00:00
[EXIF]          OffsetTime                      : -07:00
[EXIF]          OffsetTimeOriginal              : -07:00
[EXIF]          OffsetTimeDigitized             : -07:00
[Composite]     SubSecCreateDate                : 2023:04:16 12:00:00-07:00
[Composite]     SubSecDateTimeOriginal          : 2023:04:16 12:00:00-07:00
[Composite]     SubSecModifyDate                : 2023:04:16 12:00:00-07:00

C:\>exiftool -overwrite_original -Progress -ext JPG -ext HEIC -ext PNG "-FileCreateDate<SubSecDateTimeOriginal" "-FileModifyDate<SubSecDateTimeOriginal" "-GPS*Stamp<SubSecDateTimeOriginal" "-XMP:CreateDate<SubSecCreateDate" "-XMP:DateTimeOriginal<SubSecDateTimeOriginal" "-XMP:ModifyDate<SubSecModifyDate" "-XMP:DateTime<SubSecDateTimeOriginal"  y:\!temp\Test4.jpg
======== y:/!temp/Test4.jpg [1/1]
    1 image files updated

C:\>exiftool -time:all --system:all -G -a -s y:\!temp\Test4.jpg
[EXIF]          ModifyDate                      : 2023:04:16 12:00:00
[EXIF]          DateTimeOriginal                : 2023:04:16 12:00:00
[EXIF]          CreateDate                      : 2023:04:16 12:00:00
[EXIF]          OffsetTime                      : -07:00
[EXIF]          OffsetTimeOriginal              : -07:00
[EXIF]          OffsetTimeDigitized             : -07:00
[EXIF]          GPSTimeStamp                    : 19:00:00
[EXIF]          GPSDateStamp                    : 2023:04:16
[XMP]           DateTimeOriginal                : 2023:04:16 12:00:00-07:00
[XMP]           DateTime                        : 2023:04:16 12:00:00-07:00
[XMP]           CreateDate                      : 2023:04:16 12:00:00-07:00
[XMP]           ModifyDate                      : 2023:04:16 12:00:00-07:00
[Composite]     SubSecCreateDate                : 2023:04:16 12:00:00-07:00
[Composite]     SubSecDateTimeOriginal          : 2023:04:16 12:00:00-07:00
[Composite]     SubSecModifyDate                : 2023:04:16 12:00:00-07:00
[Composite]     GPSDateTime                     : 2023:04:16 19:00:00Z
Title: Re: Timestamping / timezoning in windows explorer
Post by: StarGeek on April 16, 2023, 02:21:55 PM
Quote from: Tezlacore on April 16, 2023, 01:56:35 PMthis gives me a "Warning: No writable tags set from FILENAME. Nothing changed in FILENAME" error.

Is this all files or just certain ones?  That warning shouldn't happen unless there actually isn't any of the EXIF data in the file. Double check to make sure with
exiftool -time:all -G -a -s file.jpg
Title: Re: Timestamping / timezoning in windows explorer
Post by: Tezlacore on April 16, 2023, 02:45:33 PM
Quote from: StarGeek on April 16, 2023, 02:17:49 PMFor the OffsetTime tags, you'll have to figure out the quoting to make your "$Timezone" variable work correctly.  It works correctly directly on the command line, even in PS

Got it working now. I don't fully understand why/how, but basically by using quotation marks and apostrophe:
C:\exiftool.exe '-OffsetTime*="'$TimeZone'"' $targetfolder
With this running, it also made your second piece of code run smoothly.

Thanks for the (quick!) help.