Getting the modified date of a .gdb table/feature class took some real acrobatics, but I was finally able to get it done. I started out with zero ArcObjects experience but a good dose of Python and arcpy.
Step one was to carefully follow the instructions here:
How do I access ArcObjects from Python? - Geographic Information Systems Stack Exchange
and here:
python - ArcObjects + comtypes at 10.1 - Geographic Information Systems Stack Exchange
Once I got the "create point" code working (from the example in the first link), I opened up the Snippets.py code and inserted the following function under the *** Standalone *** section, where gdb is the full path to the gdb and tableName is the table name:
def GetModifiedDate(gdb, tableName):
# Setup
GetStandaloneModules()
InitStandalone()
import comtypes.gen.esriSystem as esriSystem
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB
# Open the FGDB
pWS = Standalone_OpenFileGDB(gdb)
# Create empty Properties Set
pPropSet = NewObj(esriSystem.PropertySet, esriSystem.IPropertySet)
pPropSet.SetProperty("database", gdb)
# Cast the FGDB as IFeatureWorkspace
pFW = CType(pWS, esriGeoDatabase.IFeatureWorkspace)
# Open the table
pTab = pFW.OpenTable(tableName)
# Cast the table as a IDatasetFileStat
pDFS = CType(pTab, esriGeoDatabase.IDatasetFileStat)
# Get the date modified
return pDFS.StatTime(2)
Finally, I created a script that implemented the function (set up for a custom script tool but could be used as a stand-alone as well):
import Snippets
import datetime
import arcpy
import sys
# User Params
file_gdb = arcpy.GetParameterAsText(0) # Path to FGDB
table_name = arcpy.GetParameterAsText(1) # Table or feature class name
arcpy.env.workspace = file_gdb
if file_gdb.split(".")[-1] != "gdb":
arcpy.AddMessage("The input workspace is not a file geodatabase!")
sys.exit()
def doIt(file_gdb, table_name):
# Call GetModifiedDate function to get the number of seconds
num_seconds = Snippets.GetModifiedDate(file_gdb, arcpy.Describe(table_name).baseName)
# Translate the number of seconds into a formatted date
date_modified = datetime.datetime.fromtimestamp(num_seconds).strftime('%Y-%m-%d %H:%M:%S')
# Report the result
arcpy.AddMessage(date_modified)
return date_modified
doIt(file_gdb, arcpy.Describe(table_name).baseName)
I sincerely hope this helps! Thanks to all the people who got me to an actual solution.