Select to view content in your preferred language

Dateformat

5956
18
04-13-2021 09:48 AM
Labels (3)
A_n_d_r_e_a
Regular Contributor

Dear Community,

i want to use Python to create a new date format.

I have found something on the website:

datetime.datetime(2000, 12, 31)

 

!field1! + datetime.timedelta(days=100)

 I want to try it with the both.

Does anybody know, where i should add it in the field calculator.

In the code block?

 

Sorry for my little informatic knowledge...

 

Greetings,

Andrea

0 Kudos
18 Replies
DavidPike
MVP Frequent Contributor

You could add it in the code block as a function, but it should work just fine in the normal window (just above the code block space).

You do already have a field where you're adding the 100 days to?  I'm not sure what you mean by 'new date format', and what is the 31 Dec 2000 for?

If you just want to play with the module, use an IDE or online compiler such as Online Python Compiler (Interpreter) (programiz.com)

then try things such as:

import datetime

initial_datetime = datetime.datetime(2000, 12, 31)
time_delta = datetime.timedelta(days=100)

print(initial_datetime)
print(initial_datetime + time_delta)
A_n_d_r_e_a
Regular Contributor

Hi David,

my mean Problem starts by the default time setting in ArcGIS.

If i import my netCDF than the date is imported incorrect such as double. If i create a new field in a date format, the date begins just as by default 1899 and not like my original 2019.

So i want to calculate a new field to get to my original date which is 2019-01-01 to 2020-12-31.

That 31.Dec 2000 was just an example...

0 Kudos
DavidPike
MVP Frequent Contributor

you should just be able to specify an exact date for all the rows in the correct format, such as

2019-01-01 00:00:00

However I can't really comment on NetCDF as I believe the temporal dimension is stored differently.

Hopefully there's some examples with the Make NetCDF Raster Layer tool and the dimension parameter. 

0 Kudos
A_n_d_r_e_a
Regular Contributor

...as you can see in the picture the imported netCDF and the date or "time" is shown up as double, i calculated a new field "Date" in date format with the time field, and its still not 2019...its still no the original date...

Thanks forward!

 

Greetings,

Andrea

0 Kudos
DavidPike
MVP Frequent Contributor

From your explanations I still have no idea what you want to do sorry, hopefully someone else can help.

0 Kudos
A_n_d_r_e_a
Regular Contributor

Hi David,

the thing is I choose from a satellite website some Data in netCDF Format. An I set the beginning of my time period on 2019-01-01. But instead of that it is shown up as a double value like you can see in the picture with a red border. And i want to have it like 2019-01-01. I uploaded a picture with my Problem.

Thanks forward!

Greetings,

Andrea

0 Kudos
DanPatterson
MVP Esteemed Contributor

If your time column is "days" then read on

 

d = datetime.datetime(2019, 1, 1)  # your initial date at the top 
d
datetime.datetime(2019, 1, 1, 0, 0)

time_vals = [46, 47, 48, 49]  # -- using some of the values I saw in the "time" column

# ---- now pretend this is a field calculation
# ---- look at the output, this is what would appear as you go down the column
for val in time_vals:
    new_date = d + datetime.timedelta(days = val)
    print(new_date)
    
2019-02-16 00:00:00
2019-02-17 00:00:00
2019-02-18 00:00:00
2019-02-19 00:00:00

 

I think the field calculator expression would be

 

datetime.datetime(2019, 1, 1) + datetime.timedelta(days = !time!)

 


... sort of retired...
0 Kudos
A_n_d_r_e_a
Regular Contributor

Hey Dan,

many thanks for your effort.

That is also an options to calculat an field, but I think I found my solution for my multidimensional data.

I would ask you to check my solution.

I found my solution in the link on the page of ArcGIS...

https://desktop.arcgis.com/en/arcmap/10.3/manage-data/raster-and-images/wkfl-create-a-multidimension...

So i create a Variable Field, a Dimension Field with "StdTime". Now there is also a little Problem with understanding Python...

I uploaded a picture with a red mark, which doesnt fit to my date I think...if i put this inside the Code Block and click ok, its written there something with invalid parameter? So the date should retrieved but how which syntax?

Thanks forward!

Greetings,

Andrea

 

 

 

0 Kudos
A_n_d_r_e_a
Regular Contributor

Your "days" column in which type has it to be?

0 Kudos