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"
Checking the created time for the date and comparing to todays date?
-
14-10-2022 - |
Domanda
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?
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow