AnsweredAssumed Answered

Using python delete old tables with date and time in table's name

Question asked by sehafiz on Aug 7, 2019
Latest reply on Aug 13, 2019 by sehafiz

I have been using ArcGIS 10.3.1.


I have a list of tables in an enterprise geodatabase with date and time in the table name. Every day one table is created, as an outcome of some geoprocessing tasks with the date and time in the table’s name when the table is created.


Naming format of the tables are FHRT_YYYYmmdd_HHMMSS



  1. FHRT_20190808_071015 (this table is created on 08 August 2019 at 07:10:15)
  2. FHRT_20190807_071218 (this table is created on 07 August 2019 at 07:12:18)
  3. FHRT_20190806_071119
  4. FHRT_20190805_071913
  5. FHRT_20190804_071418
  6. FHRT_20190803_071014
  7. FHRT_20190802_070815



I want to create a python script that will keep the latest 3 tables (in this example FHRT_20190808_071015, FHRT_20190807_071218 and FHRT_20190806_071119) and delete the rest with similar name format. The geodatabase may have other tables with other name format (cadastre, property etc.), I do not want to touch those.


Being new in Python I do not know how I would create the script that will specify the dates.


I mean how will I instruct the script to keep the 3 tables that have the latest dates and delete the older tables?


What module do i need to import and what would be the statement?


Thank you in advance.