如何使用da.searchcursor选择小时和分钟= 0的行

问题描述:

我想从arc.sde数据库中的众多表中排除一些结果,并且唯一可以使用的字段是日期字段。我研究了Python2网站并试图了解关于日期时间等的第8.1页,但尚未能实现我的目标。 (使用Win 7的时,ArcGIS 10.2的Python 2.7.5和混合操作系统环境)如何使用da.searchcursor选择小时和分钟= 0的行

下面的代码运行正常.....

with arcpy.da.SearchCursor(fc, ['LASTEDIT_ON']) as cursor: 
    for row in cursor: 
      if row[0] <> None: 
        print str(row[0]) 

但我需要它来排除返回的行,其中小时/分钟/秒都是00:00:00。

2014-05-13 16:16:34 
2014-09-26 11:45:15 
2015-06-18 14:47:05 
2015-02-03 10:38:50 
2008-03-10 00:00:00 
2007-06-06 00:00:00 

我试着给我的代码添加小时和分钟,但我完全在错误的轨道上,我认为。错误如下。

if row[0] <> None and datetime.hour <> 0: 

Error Info: 
'module' object has no attribute 'hour' 

如果你的日期字段是一个真正的日期字段,而不是一个文本框,下面的代码将打印日期以小时,分钟和秒都空:

import arcpy 
with arcpy.da.SearchCursor(fc, 'LASTEDIT_ON') as cursor: 
    for row in cursor: 
     if row[0].hour == 0: 
      if row[0].minute == 0: 
       if row[0].second == 0: 
        print row[0] 
+0

完美的感谢@GISGe。我还在'cursor in cursor:'的行中添加了一行,以说明一个数据集中某些行实际上为null的实例。这是额外的行,如果row [0] None: – user1995458