Select to view content in your preferred language

How to print a Date field from an AGOL hosted feature in Notebook

260
1
Jump to solution
06-28-2024 10:35 AM
SanchezNuñez
Frequent Contributor

Good afternoon,

I have a Date field in a hosted Feature layer and I do not know how to print it correctly.  It returns an integer, I would like to see the date.

 

# Access the first layer in the feature layer item (if it has multiple layers)
feature_layer = feature_layer_item.layers[0]
feature_layer

# Query the layer for a specific record
# For example, to find a record with OBJECTID = 1
query = feature_layer.query(where="OBJECTID = 1")

record = query.features[0]
print(record.attributes)

# Date field
lastUpdateAGOL = record.attributes["LAST_UPDAT"]
lastUpdate_dateonly = lastUpdateAGOL.date()   ====> Returns an error

 

 

0 Kudos
1 Solution

Accepted Solutions
SanchezNuñez
Frequent Contributor

Found it:

# Convert the timestamp to a datetime object
date_value = datetime.utcfromtimestamp(lastUpdateAGOL / 1000) # if the timestamp is in milliseconds

# Print the human-readable date
print(date_value.strftime('%Y-%m-%d %H:%M:%S'))

View solution in original post

0 Kudos
1 Reply
SanchezNuñez
Frequent Contributor

Found it:

# Convert the timestamp to a datetime object
date_value = datetime.utcfromtimestamp(lastUpdateAGOL / 1000) # if the timestamp is in milliseconds

# Print the human-readable date
print(date_value.strftime('%Y-%m-%d %H:%M:%S'))

0 Kudos