JokerMartini JokerMartini - 22 days ago 10
Python Question

Test if modified file time is within 2 days in Python

How can I test whether a file has been modified within the past 2 days or less using Python?

import os
file_time = os.path.getmtime('test1.jpg')

# pseudo...
if file_time <= ??:
return true

Answer

Here is a way to do it:

import time
difference = (time.time() - file_time) / (60 * 60 * 24)
if difference <= 2:
    return True
Comments