Python Program to Get File Creation and Modification Date

To understand this example, you should have the knowledge of the following Python programming topics:


Example 1: Using os module

Output

Last modification time: Mon Apr 12 10:43:24 2020
Last metadata change time or path creation time: Mon Apr 12 10:43:24 2020

getmtime() gives the last modification time whereas getctime() gives the last metadata change time in Linux/Unix and path creation time in Windows.


Example 2: Using stat() method

Output

Last modification time: 2021-04-12 10:43:24.234189
Last metadata change time or path creation time: 2021-04-12 10:43:24.234189

Similar to Example 1, st_mtime refers to the time of last modification; whereas, st_ctime refers to the time of the last metadata change on Linux/Unix and creation time on Windows.