Is there a way to get the date a file geodatabase was created? Windows file explorer properties shows the correct creation date but os.path.getctime() just seems to return the same thing as os.path.getmtime(): the date modified ( which gets changed every time you view something in the gdb). Workspace Describe doesn't have anything either.
Solved! Go to Solution.
Can you give an example where Windows Explorer gives different creation and modification dates but Python returns the same date for both?
I am running ArcMap 10.4 (Python 2.7.10) on Windows 7 x64 Enterprise Edition, and Python returns the same dates as Windows Explorer:
>>> from time import ctime
>>> from os.path import getmtime, getctime, split
>>> gdb = # path to file geodatabase
>>> print "{}\t{}\t{}".format(split(gdb)[1],
... ctime(getmtime(gdb)),
... ctime(getctime(gdb)))
...
Default.gdb Sat May 21 10:45:21 2016 Wed Feb 10 08:43:54 2016
>>>
never checked it... but are you saying that the path to *.gdb is being treated like a file? because folders don't change time when their contents change... now I will have to check.
Just noticed there is a gdb file in the geodatabase that seems to retain the earliest time of the geodatabase. I'm going with that unless anyone else has a better suggestion.
What I do is inspect every file in the GDB, look at the time stamp, adjust for daylight saving to get UTC and go with that. You'll need to go deep depending on your workflow.
Bruce
Sent from my Lumia 830
Here's a function to get that creation date by finding the minimum file date.
This function will work on any "folder" dataset like .gdb, grid, coverage, as it returns the earliest creation date of all files in the folder.
def create_date(gdb): import os import time import glob first_time = min([os.path.getctime(f) for f in glob.glob(gdb + "/*")]) # return the time t = time.localtime(first_time) # or a string t = time.strftime("%c", time.localtime(first_time)) return t
Can you give an example where Windows Explorer gives different creation and modification dates but Python returns the same date for both?
I am running ArcMap 10.4 (Python 2.7.10) on Windows 7 x64 Enterprise Edition, and Python returns the same dates as Windows Explorer:
>>> from time import ctime
>>> from os.path import getmtime, getctime, split
>>> gdb = # path to file geodatabase
>>> print "{}\t{}\t{}".format(split(gdb)[1],
... ctime(getmtime(gdb)),
... ctime(getctime(gdb)))
...
Default.gdb Sat May 21 10:45:21 2016 Wed Feb 10 08:43:54 2016
>>>
I tried your code, Joshua, and it seems to work fine. I'm not sure what I was doing; I must have had a brief infection of Friday afternoon derp derp.
However, since I'm already using datetime, I'll use that instead of time.
import datetime import os gdb = # path to file geodatabase created_timestamp = os.path.getctime(gdb) print datetime.datetime.fromtimestamp(created_timestamp)