I want to create a new field with years data. There is an existing field with the timestamp YYYYMMDDHHMM. But I just want the years from that field to the new field. That way I can display just the years when I create a graph. IS there anyone that can explain the code to do this. I am not a programmer and need the scripts or python code explained as if I were a 5-year old. Thank you.
|
|
Assuming your existing timestamp field is a string:
Note that you need to replace the "ExistingTimeStampField" between the exclamations with the actual name of your field (should be able to auto-populate in the Fields list box). This will trim off the leading 4 characters from your existing field which I presume will always be the 4-digit year. Edit: If you wish to break out more information you can simply update the indices of your query like such (Note that my original [:4] is the same as saying [0:4]):
This would return the MM in YYYYMMDDHHMMSS. [6:8] would return the DD, and so on. See here for a more detailed explanation of substrings: http://docs.python.org/tutorial/introduction.html#strings |
|||||||||
|
|
If your field type is a string that contains data formatted exactly as you said, then filling your new field is a relatively simple matter of parsing out the string. Since you did not specify, I'll give options in both the ArcGIS, and Quantum GIS software packages, depending on what you are using. ArcMap In this case, the Right click on the name of your new field, and choose "Field Calculator". Type in what you see from the screenshot below. Replace
Quantum GIS
|
||||


