Arcgis datetime format python

508
7
10-12-2021 08:08 PM
GarretVo
New Contributor

Hi all,

    I use python to export my data into arcgis online. I am struggling with the time column. Every time I export, the time column is still registering as string. I am quite lost. Can anyone help? I would appreciate it. My code is below for one time instance is below:

     time_data = datetime.datetime(2021, 4, 22, 12, 1)

      time_reformat = datetime.datetime.strftime(time_data,'%Y/%m/%d %H:%M:%S')

The variable tim

0 Kudos
7 Replies
GaryStaker1
New Contributor II

Your time_data variable is a datetime object and the time_reformat variable is a string object.

Is this not what you are expecting?

 

0 Kudos
GarretVo
New Contributor

Hi Garry,

   I expect the time_reformat variable is a string, but  with the format as described the following link:

https://doc.arcgis.com/en/arcgis-online/manage-data/work-with-date-fields.htm

the time_reformat should become date type when the data is imported into ESRI. Can you please let me know what I got wrong? 

0 Kudos
BlakeTerhune
MVP Regular Contributor

Are you importing the time_reformat value into a date field in Esri? In my experience, you can use the raw datetime object in a date field, no need to reformat it.

0 Kudos
GarretVo
New Contributor

Yes I am. Correct me if I am wrong. Basically, I can put the variable time_data into date field without any issues. Can you please let me know? Thanks 

0 Kudos
BlakeTerhune
MVP Regular Contributor

Correct. Are you using an insert cursor?

0 Kudos
GarretVo
New Contributor

Hi all. I figure it out. Thank you for all your help. I just have one more question. When I export my data to arcgis online, the time is displayed as  8 hour ahead. Do you know how to change that to the original time in my data ? Thanks 

For example, in my data, the time column is 4/22/2021 12:01:00. When the data comes into arcgis, the time column is 4/22/2021 8:00 PM. I want the time to be 12:01:00. Do you guys have any ideas? Thanks  

0 Kudos
BlakeTerhune
MVP Regular Contributor

Work with date fields—ArcGIS Online Help | Documentation

All dates in ArcGIS Online are assumed to be UTC. You might need to convert the time before you upload the data.

0 Kudos