Select to view content in your preferred language

row_value = row[cursor.fields.index("LAST_UPDAT")] returns an integer

61
2
Thursday
SanchezNuñez
Occasional Contributor

Good afternoon

I am trying to read this field that stores a date. It prints as an integer, I cannot convert it to a date. 

Please advise

with arcpy.da.SearchCursor(feature_class, ["*"],where_clause ) as cursor:
for row in cursor:

row_value = row[cursor.fields.index("LAST_UPDAT")]   

rowdate_only = row_value.date()    -- This fails

 

 

0 Kudos
2 Replies
DavidSolari
Occasional Contributor III

Please make use of code sample formatting for Python code to avoid indent ambiguity, like so:

with arcpy.da.SearchCursor(feature_class, ["*"], where_clause) as cursor:
    for row in cursor:
        row_value = row[cursor.fields.index("LAST_UPDAT")]
        rowdate_only = row_value.date()  # This fails

What's the data type of "LAST_UPDAT"? If it's a string you'll need to use the this method, if it's an integer that represents a UNIX timestamp try something in this StackOverflow thread, and if it's a custom integer representation then parsing is non-trivial.

0 Kudos
SanchezNuñez
Occasional Contributor

Good morning @DavidSolari 

Environment:

Field Name: USERID, Field Type: Integer

Field Name: LAST_UPDAT, Field Type: Date,  with value 1/31/2023 4:58:00.000 PM

SDE database in Ms SQS Server

Workstation and servers running in Windows

I am reading records from an SDE layer located in a Ms SQL Server database, and my goal is to update the same record on a AGOL hosted feature.   I am reading all records from SDE using arcpy.da.SearchCursor, then searching using USERID field in the hosted feature and comparing  dates using LAST_UPDAT field.

The compare dates does not work, something is missing.

My questions:

  • is the field date stored in the same way in AGOL and in SDE?  I am getting an integer for SDE and a data for AGOL
  • Do I need to do a conversion when I store the field LAST_UPDAT from SDE to AGOL?

 

Thanks

 

 

 

 

 

 

0 Kudos