Select to view content in your preferred language

AGOL Date fields how to convert them to strings

174
3
Jump to solution
12-04-2024 07:10 AM
JoseSanchez
Frequent Contributor

Good morning,

date fields when I read a recorrd froma hosted layer in AGOL have nummeric values:

this is the value for this field: "created_date": 1719488318485

Python:

record = query_result1.features[0]
createddateAGOL = record.attributes["created_date"]

How do I convert this numeric value to a data that I can compare with a record from a SDE feature  class 

Thanks

 

 

 

0 Kudos
1 Solution

Accepted Solutions
MobiusSnake
MVP Regular Contributor

Use this to convert to a date/time object:

from datetime import datetime as dt

created_date = record.attributes["created_date"]
my_dt = dt.utcfromtimestamp(created_date / 1000)

From there, there are various date/time formatting options:

https://docs.python.org/3/library/datetime.html#format-codes

View solution in original post

3 Replies
MobiusSnake
MVP Regular Contributor

Use this to convert to a date/time object:

from datetime import datetime as dt

created_date = record.attributes["created_date"]
my_dt = dt.utcfromtimestamp(created_date / 1000)

From there, there are various date/time formatting options:

https://docs.python.org/3/library/datetime.html#format-codes

JoseSanchez
Frequent Contributor

 

Thank you @MobiusSnake 

How do I store a datetme object  value in a date field from a hosted feature layer?

I am updating the value of a date field in a hosted feature layer using Python.

Thanks

0 Kudos
MobiusSnake
MVP Regular Contributor

You can pass a date/time value directly into a method like edit_features or you can pass a timestamp in the same format that the query returned it in.

0 Kudos