avHow to retrive the modification date of an ArcSDE elements?

3365
12
08-07-2015 06:11 AM
SaidAkif
New Contributor III

Hi all,

I work with an arcSDE database (SQL server Enterprise geodatabase) and I want to retrive using python code the modification date of each of its elements (tables, features classes, rasters, ...)

Thanks

Reply
0 Kudos
12 Replies
ChristianWells
Esri Contributor

Hi Said,

When you say modified date, do you mean table structure or last updated/added row?

Reply
0 Kudos
SaidAkif
New Contributor III

I Mean last feauture class modification or the date of creation

Thanks for your quick answer

Reply
0 Kudos
ChristianWells
Esri Contributor

Hi Said,

This is something that can be done by sending SQL queries to your SDE repository tables to get the created UNIX time from the sde_table_registry and convert that to a more standard time. I have attached a script I have used to perform this in the past and write it out to a logfile.

However, this should be enough to get you started on how to access and convert the registration time in your Enterprise Geodatabase.

import arcpy, os, datetime, time

workPath = r"Database Connections\Connection to cwells.sde"

arcpy.CreateDatabaseView_management(workPath, viewName, "select database_name, owner, table_name, registration_date from sde.sde_table_registry")

for row in arcpy.SearchCursor(os.path.join(workPath, viewName)):

    tableName = row.getValue("DATABASE_NAME") + "." + row.getValue("OWNER") + "." + row.getValue("TABLE_NAME")

    cDate = row.getValue("REGISTRATION_DATE")

    dTime = time.strftime('%d-%b-%Y %H:%M:%S', time.localtime(cDate))

SaidAkif
New Contributor III

Thanks

Is there a possibility to have just one date or the date creation or a last modification of a feature class instead of looping in all rows

Reply
0 Kudos
ChristianWells
Esri Contributor

I'm not sure of your exact question, but are you asking if its possible to return a date for a single feature class only?

Reply
0 Kudos
SaidAkif
New Contributor III

Some time you want to know the date when a feature classe was added to a dataset or when was its last modification. it is about those kind of information

Reply
0 Kudos
ChristianWells
Esri Contributor

Here is a sample of a single feature class:

import arcpy, os, datetime, time

gdb = r"Database Connections\Connection to cwells.sde"

conn = arcpy.ArcSDESQLExecute(gdb)

owner = 'sde'

table = 'alex'

sql = """SELECT

create_date,modify_date

FROM sys.tables

where UPPER(SCHEMA_NAME(schema_id)) = '{0}' AND

  UPPER(OBJECT_NAME(object_id)) = '{1}'"""

dates = conn.execute(sql.format(owner.upper(), table.upper()))

print (owner + '.' + table).upper()

print "Create Date: {0}".format(dates[0][0])

print "Modify Date: {0}".format(dates[0][1])

OUTPUT

SDE.ALEX

Create Date: 8/3/2015 10:55:11 AM

Modify Date: 8/3/2015 11:00:51 AM

SaidAkif
New Contributor III

Sorry but how can I try it with a single feature class

Thanks

Reply
0 Kudos
ChristianWells
Esri Contributor

You can change the "owner" and "table" variables to be your feature class, table or raster.

So if the feature class you want to get information for appears as "gis.abc.polygons" the variable would be:

owner = 'abc'

table = 'polygons'

Reply
0 Kudos