Over a million developers have joined DZone.

Change System Date Of Photos To EXIF Date

This script takes a list of files as arguments.
It set the system datetime (both modifitation and access) to the date 
the photo was taken.

It use the EXIF module for that, that needs to be in the same folder as the script :
You can find it here :


import sys
import EXIF
from datetime import *
import time
import os

# Loop on arguments (files)
for arg in sys.argv[1:] :
    # Do nothing of dirs
    if os.path.isdir(arg) :

    # Open the file
    f=open(arg, 'rb')
    # Read exif data
    tags = EXIF.process_file(f)
    # Ensure date is present 
    if not tags.has_key("Image DateTime") :
    # Get date of photo
    date = tags["Image DateTime"]
    date = datetime(*(time.strptime(date.values, "%Y:%m:%d %H:%M:%S")[0:6]))
    timestamp = int(time.mktime(date.timetuple()))
    # Some traces
    print "File:%s - Time:%s " % (arg, timestamp)

    # Change the date
    os.utime(arg, (timestamp, timestamp))


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}