On 17 Jan 2007 08:31:07 -0800, [EMAIL PROTECTED] wrote: > >Thanks a mill - os.path.getctime(f) is what I needed. Unfortunately, my >attempts to turn the integer it returns into a date have failed. > >>>> os.path.getctime(fn) #fn was created today, 1/17/2007 >1168955503 > >I tried to convert this to a date object by typing >>>>datetime.date.fromordinal(1168955503) > >Traceback (most recent call last): > File "<pyshell#9>", line 1, in -toplevel- > datetime.date.fromordinal(1168955503) >ValueError: year is out of range > >How can I do the conversion? I'm trying to identify all files that were >created after YYYY/MM/DD. > >For a quick sanity check, I ran >>>> datetime.date.today().toordinal() >732693 > >which is orders of magnitude smaller than the number returned by >os.path.getctime(fn). > >Thanks in advance for your help
Ordinals are unrelated to the values given back by getctime. Try something like this instead: [EMAIL PROTECTED]:~$ python Python 2.4.3 (#2, Oct 6 2006, 07:52:30) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> import datetime >>> datetime.date.fromtimestamp(os.path.getctime('.')) datetime.date(2007, 1, 17) >>> [EMAIL PROTECTED]:~$ ls -ld . drwxr-xr-x 93 exarkun exarkun 8192 2007-01-17 10:34 . [EMAIL PROTECTED]:~$ Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list