Dateformat

4775
18
04-13-2021 09:48 AM
A_n_d_r_e_a
New Contributor III

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
A_n_d_r_e_a
New Contributor III

Hi Dan,

can you please complete this script with a 24 hours loop? I searched everywhere for that but I can`t find...

So just like

2019-01-01 00:00:00

2019-01-01 01:00:00

2019-01-01 02:00:00

...and so on

End date should be 2020-12-31 23:00:00

 

Thanks,

Regards,

Andrea

0 Kudos
DanPatterson
MVP Esteemed Contributor

The codeblock isn't properly formatted in the link.

 

 

def getDate(name):
    year = name[18:22]
    month = name[23:25]
    return time.strftime("/".join(["1", month, year]))

 

Now in your expression you have ....!Name!  is that the name of the field?  If not replace it with the name of the field you want to use

Also you might want to check or provide a sample of your field because the slicing needs to be checked (eg name[18:22]

 


... sort of retired...
0 Kudos
A_n_d_r_e_a
New Contributor III

Hey Dan,

you know, the Name is the Name of the field with the NO2 concentration. The last sentence i don`t understand. Please can you explain it a little bit more? What is (eg name[18:22]?

Greetings,

Andrea

0 Kudos
DanPatterson
MVP Esteemed Contributor

for the script to work the field has to contain the date information in it. 

I don't see that in your "name" field.

There are no numbers that represent the year or month.

I can't work off screen grabs of information to copy and paste to provide an example.

Nothing so far has helped. Unless you have what is needed by the function, I have nothing further to add.


... sort of retired...
0 Kudos
A_n_d_r_e_a
New Contributor III

Hey Dan,

ok now I get you. But what I don`t understand is...

year = name[18:22]

month = name[23:25]

what does these numbers mean?

I can`t read it in the link.

Thanks forward!

 

Greetings,

Andrea

0 Kudos
DanPatterson
MVP Esteemed Contributor

the 18 to 22 characters in "name" are the year

the 23 to 25 characters in "name" are the month


... sort of retired...
0 Kudos
A_n_d_r_e_a
New Contributor III

Hey Dan,

thanks for the info...I just uploaded a picture. There you can see the Datum field an StdTime which I create. Both in Date format. On the right side there you can see the def getDate(Datum):

def getDate(Datum):
year = Datum[18:22]
month = Datum[23:25]
return time.strftime("/".join(["1", month, year]))

Is that right like this? Than there is also still the Problem to convert it to my orginial time from 2019-2020.

Thanks forward!

Greetings,

Andrea

 

 

0 Kudos
DavidPike
MVP Frequent Contributor

have you tried the script Dan provided? it looks like it would work exactly as needed using your day integer values.

0 Kudos
A_n_d_r_e_a
New Contributor III

I just realized now that my date field is a double type, so it should be possible to use the toolbox "convert time field". I just opened the netCDF data with Panoply and the data is there in a 20190101 format and its written there als float type. Does that help? Of course I also have to keep attention to the locale. So I need a formate where I can use also with the time controller. So the best format would be JJJJ/MM/TT hh:mm:ss because I have data for every hour.

Here is the link where I get the information...

https://desktop.arcgis.com/de/arcmap/latest/map/time/convert-string-or-numeric-time-values-into-date...

https://pro.arcgis.com/de/pro-app/latest/help/mapping/time/supported-field-formats.htm

 

Thanks forward!

Greetings,

Andrea

 

0 Kudos