# Help me calculate field records with small python code

629
5
09-14-2023 06:03 AM
Labels (3)
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)
1 Solution

Accepted Solutions
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:

With your sample values, I get:

5 Replies
Esri Regular Contributor

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

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

New Contributor II

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

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

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:

With your sample values, I get:

New Contributor II

Thank you so much 😍