Help me calculate field records with small python code

629
5
Jump to solution
09-14-2023 06:03 AM
Labels (3)
shotatskhovrebashvili
New Contributor II

I have a python code that works for a single record:

from datetime import datetime, timedelta
utc = datetime(1980, 1, 6) + timedelta(seconds=1325841623 - (35 - 17))
print(utc)

Result: 2022-01-10 09:20:05

How can I modify the code so it can calculate each record in the field by that formula?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

Okay, so all you have to do is pop open your Field Calculator, write a simple function, and apply to your target date field like so:

EarlMedina_0-1694708186311.png

 

With your sample values, I get:

EarlMedina_1-1694708225174.png

 

View solution in original post

5 Replies
EarlMedina
Esri Regular Contributor

What's the input/value that changes across the records? Is it the date (1980, 1, 6)?

0 Kudos
shotatskhovrebashvili
New Contributor II

The input values are GPS seconds, like: 1325841623 and after using the formula you get the date in UTC: 2022-01-10 09:20:05

0 Kudos
shotatskhovrebashvili
New Contributor II

I have thousands of records to be converted. Here are few examples:

1325841623; 1325841625; 1325841626; 1325841627; 1325841628; 1325841629; 1325841630; 

 

0 Kudos
EarlMedina
Esri Regular Contributor

Okay, so all you have to do is pop open your Field Calculator, write a simple function, and apply to your target date field like so:

EarlMedina_0-1694708186311.png

 

With your sample values, I get:

EarlMedina_1-1694708225174.png

 

shotatskhovrebashvili
New Contributor II

Thank you so much 😍