How to get file creation and modification date and times in Python?

  • Get the time of last modification :

import os
result = os.path.getmtime(path)

The function returns a value which is the number of seconds since the epoch.

  • Get the time of file creation :

result = os.path.getctime(path)

The function returns a value which is the system’s ctime which, on Unix and Linux systems is the time of the last metadata change. While on Windows it is the creation time. The return value is the number of seconds since the epoch.

Both functions raise OSError if the file does not exist or is inaccessible.

Both have been changed in version 3.6 to accepts a path-like object.

  • More information:

How to convert epoc time to human readable format.

  • DONE!


  • Minimum Requirements and How-to:

  • Python3

Leave a Reply