Select to view content in your preferred language

Date query on File GDB

1232
3
Jump to solution
08-31-2012 10:08 AM
KevinBell
Deactivated User
I'm getting aggravating results trying to query a date time field in a fgdb...

If I use this:

"gpstime" > date '2011-06-14 10:00:00' AND "gpstime" < date '2011-06-14 11:00:00'

in the select by attributes dialog in arcmap it works fine, but using it as the whereclause in
arcpy.SelectLayerByAttribute i get the wrong times. 

ideas?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KevinBell
Deactivated User
User Error!  I shouldn't program on Friday afternoons!  I just had a problem buried in the routine that builds the query.

View solution in original post

0 Kudos
3 Replies
KevinYanuk
Deactivated User
I'm getting aggravating results trying to query a date time field in a fgdb...

If I use this:

"gpstime" > date '2011-06-14 10:00:00' AND "gpstime" < date '2011-06-14 11:00:00'

in the select by attributes dialog in arcmap it works fine, but using it as the whereclause in
arcpy.SelectLayerByAttribute i get the wrong times. 

ideas?



There might be an issue with the quotations.  You could try to set it as a string variable, and passing the variable as the query:

query = "\"gpstime\" > date '2011-06-14 10:00:00' AND \"gpstime\" < date '2011-06-14 11:00:00'"

arcpy.SelectLayerByAttributes_management(lyr, "NEW_SELECTION", query)


edit:  notice the slashes I used in the query string to ignore ending the full string
0 Kudos
KevinBell
Deactivated User
I am actually passing it in as a variable.  I build the string up programmatically and print the whereclause using addMessage and this is how it prints out, which works if using the query builder.
0 Kudos
KevinBell
Deactivated User
User Error!  I shouldn't program on Friday afternoons!  I just had a problem buried in the routine that builds the query.
0 Kudos