Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get days between dates

I need to remove files that are older than 14 days from a directory that stores our backups. I can get the time of an individual file by using something like this:

start = (os.path.getmtime(join(dirpath, name))/3600*24)  

But I'm getting confused with how I use timedelta to find the difference between this and the current date.

I'd like to use something like this:

d = (datetime.timedelta(time.now() - os.path.getmtime(join(dirpath, dirname))  

but I'm just not getting it. I'm on my own here, and I'd love some help.

like image 607
JLP Wisc. Avatar asked Oct 16 '25 13:10

JLP Wisc.


1 Answers

Try:

if time.time() - os.path.getmtime(filename) > 14 * 24 * 3600:
  print 'the file is older than 14 days'
like image 107
NPE Avatar answered Oct 19 '25 10:10

NPE