0

I want to create a function that is going to search for metadata of JPG files using exifread, select the earliest date from Image DateTime tag and print it. Here is the code I have so far (not much :D):

def GetExifTagsForFile(filename):
  file = open(filename,'rb')
  tags = exifread.process_file(file)

Usually, I would further create a list where I add all dates and then using min select the earliest date. However, here I am trying to operate with IfdTag for which this kind of solution will not work. The encoding of IfdTag is %Y:%m:%d %H:%M:%S. I have also tried to change tag's format to datetime using strdtime, however, this solution works only for strings. Do you have any suggestions how to solve my problem?

Kirill
  • 1
  • 3

1 Answers1

1

As pointed out by @SiHa this depends on how your tag is encoded. I think it should be "YYYY:MM:DD HH:MM:SS". In this case bring your tags first to string and then to datetime format, where you can use min():

from datetime import datetime

datetime_objects = [datetime.strptime(str(t['IfdTag'].values), '%Y:%m:%d %H:%M:%S') for t in tag_list]
min(datetime_objects)
Nyps
  • 831
  • 1
  • 14
  • 26