Get date and time when photo was taken from EXIF data using PIL

exif, python, python-imaging-library

Solution

Found the answer eventually, the tag I needed was 36867:

from PIL import Image
def get_date_taken(path):
    exif = Image.open(path)._getexif()
    if not exif:
        raise Exception('Image {0} does not have EXIF data.'.format(path))
    return exif[36867]

This works for me on both the old "PIL", and the new "Pillow" fork.

Problem

I can get the EXIF data from an image using PIL, but how can I get the date and time that the photo was taken?

Original source

Related problems