Question

I've not got very far with this, I'm trying to check the creation time of a file and simply compare the date (only the day, month and year) with todays date (again only day, month and year)

import os.path, time
import datetime
fulldate = time.ctime(os.path.getctime("file.xlsx"))

Anyone know how I can convert the date and then check against todays date?

Was it helpful?

Solution

import os.path, time
from datetime import datetime
from time import mktime

fulldate = time.ctime(os.path.getctime("file.xlsx"))
struct = time.strptime(fulldate)
filetime = datetime.fromtimestamp(mktime(struct))
filedate = filetime.replace(hour=0, minute=0, second=0, microsecond=0)

if filetime < datetime.now():
  print "The file is quite old"
else:
  print "The file is not so old"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top