File geodatabase creation date

6948
6
Jump to solution
05-20-2016 02:11 PM
BlakeTerhune
MVP Regular Contributor

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.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

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:

windows_explorer_default_gdb_dates.PNG

>>> 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
>>>

View solution in original post

6 Replies
DanPatterson_Retired
MVP Emeritus

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.

0 Kudos
BlakeTerhune
MVP Regular Contributor

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.

0 Kudos
BruceHarold
Esri Regular Contributor

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

curtvprice
MVP Esteemed Contributor

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
JoshuaBixby
MVP Esteemed Contributor

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:

windows_explorer_default_gdb_dates.PNG

>>> 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
>>>
BlakeTerhune
MVP Regular Contributor

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)
0 Kudos