GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Get file creation and modification date/times - w3resource

Python: Get file creation and modification date/times

Last update on May 17 2025 05:43:26 (UTC/GMT +8 hours)


File Timestamps

Write a Python program that retrieves the date and time of file creation and modification.

Sample Solution:

Python Code :

# Import the 'os.path' and 'time' modules to work with file system paths and timestamps.
import os.path, time

# Print the last modified timestamp of the file "test.txt" in a human-readable format.
print("Last modified: %s" % time.ctime(os.path.getmtime("test.txt")))

# Print the creation timestamp of the file "test.txt" in a human-readable format.
print("Created: %s" % time.ctime(os.path.getctime("test.txt")))

Sample Output:

Last modified: Wed Apr 19 11:36:23 2017                                                                       
Created: Wed Apr 19 11:36:23 2017 

Flowchart:

Flowchart: Get file creation and modification date/times.


For more Practice: Solve these Related Problems:

  • Write a Python program to find the last access time of a given file.
  • Write a Python program to get the timestamp of a file and convert it into a human-readable format.
  • Write a Python program to compare the creation times of two different files.
  • Write a Python program to check if a file has been modified in the last 24 hours.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to get an absolute file path.
Next: Write a Python program to convert seconds to day, hour, minutes and seconds.

Python Code Editor:

 

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.