Edit capture date and time by using information from file name

First: I moved successfully from Lightroom to Darktable :slight_smile:

I imported a lot of images where I miss the capture date in the EXIF data. Therfore chronologic sorting is not possible.
However the filename contains the capture data and time. E.g. 20230311_153804 or 2014-04-08 12.04.28.
Is there any chance to tell darktable to read the information from the filename and change the capture date and time in EXIF?
Thanks, Andreas

Raw files or jpg?

Currently, dt does not use the filename to populate metadata. You might look into Exiftool.

Welcome to the forum! It’s a treasure of tips and tricks :slight_smile:

I think Darktable can’t do this, but you should be able to do this with “exiftool” on the command line. Do all files have the same filename scheme? Then it should be possible to process all files in one go (make sure you have a backup…)

I wonder if Digikam has some capabilities to do the job.

Well, changing the original capture timestamp is not something you usually want to do. In addition, changing metadata in raw files isn’t recommended.
Afaik, neither digikam nor darktable have a method to set timestamps from the filename. Darktable, afaik, refuses to write to original files (i.e. any file imported into it). Digikam will write to files, including some raw formats, but wont’t parse the filename.

Exiftool can set a new timestamp,but you’ll probably need to parse the filenames to extract the timestamps into the proper format for exiftool. Not sure if a shell script is powerful enough for that job.

See https://exiftool.org/faq.html#Q5:

exiftool “-alldates<filename” c:\images

could already work for the images with names such as 20230311_153804.ext

There is this but its a bit of manual intervention…

https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/image_time/

They are all jpg files

Thanks for your fast replies. Will try them.

Do you still have the raws? Can you export them again from lightroom but keeping the metadata?

no, don’t have the raws anymore.

This can be done with a lua script. The filename can be read, parsed, and the exif_datetime field in the image database record updated. The image file isn’t modified in any way.

If you send me a list of filenames with all the patterns used for date time, I can write the script.

Hi Bill, thanks a lot for your support.

The filenames are like the following:

20230311_153804.jpg [YYYYMMDD_hhmmss].jpg
2014-04-08 12.04.28.jpg [YYYY-MM-DD hh.mm.ss].jpg
CameraZOOM-20140824134314003.jpg CameraZOOM-[YYYYMMDDhhmmss]xxx
IMG-20170813-WA0011.jpg IMG-[YYYYMMDD]-xxxxxx.jpg

Here’s the script,
EXIFtime_from_fname.zip (785 Bytes)

Unzip it and drop the lua file in your contrib directory (~/.config/darktable/lua/contrib or %LOCALAPPDATTA\darktable\lua\contrib).

Start darktable and use script_manager to start the script.

Go to Settings->Shortcuts->Lua Scripts and assign shortcuts to the selection and collection items. You can the use the shortcuts to either select some images and the use the selection shortcut, or just do the whole collection with the collection shortcut.