Select to view content in your preferred language

Concatenate Julian Day + Year to get Date

3997
10
Jump to solution
07-01-2019 12:59 PM
AurelieShapiro
Frequent Contributor

I am looking for an Arcade or python code (for use in Calculate Value in ModelBuilder) to concatenate two fields of an attribute table:

-Julian Day (1-365)

-Year (YYYY)

to calculate a field with a date (mm/dd/yyyy)

I tried Convert time field and it just made all my dates January 1 2001. 

Can anyone help? 

Thank you!!

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Aurelie Shapiro ,

This would be the way you could use Arcade to get the date:

// input data from feature attributes
var year_value = $feature.Def_Year;
var julian_day = $feature.grid_code;

var year_date = Date(year_value, 0, 1);  // create date using first day of year
var final_date = DateAdd(year_date, julian_day, 'days');  // add the julian days
return final_date;‍‍‍‍‍‍‍

View solution in original post

10 Replies
RandyBurton
MVP Alum

You might try something like:

from datetime import datetime

dt = datetime.strptime('6/1/2019', '%m/%d/%Y')
tt = dt.timetuple()
print "{}-{}".format(tt.tm_yday, tt.tm_year)
# prints:  152-2019‍‍‍‍‍‍‍‍‍‍‍‍

See also: Extract day of year and Julian day from a string date

AurelieShapiro
Frequent Contributor

Thanks! Timetuple seems to be getting there.

But my two field are Julian Date of the year (dd) and year (yyyy). How do I do the opposite of what you propose? (sorry I don’t know python, I am looking for a code to integrate my two variables: dd & yyyy = dd/mm/yyyy

Thanks!

-a

Von: Randy Burton <geonet@esri.com>

Gesendet: Montag, 1. Juli 2019 22:43

An: Shapiro, Aurelie <aurelie.shapiro@wwf.de>

Betreff: Re: - Re: Concatenate Julian Day + Year to get Date

GeoNet, The Esri Community | GIS and Geospatial Professional Community <https://community.esri.com/?et=watches.email.thread>

Re: Concatenate Julian Day + Year to get Date

reply from Randy Burton<https://community.esri.com/people/rvburton?et=watches.email.thread> in Python - View the full discussion<https://community.esri.com/message/861794-re-concatenate-julian-day-year-to-get-date?commentID=861794&et=watches.email.thread#comment-861794>

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi aurelies 

You could probably use something like this:

import datetime
jul_day = 60  # will point to your field value for Julian Day
year = 2016  # will point to your field value for Year
print datetime.datetime.strptime('{}-{}'.format(year, jul_day), '%Y-%j').date()
AurelieShapiro
Frequent Contributor

do you know how to do this in Calculate field? It runs but outputs a null date...

Date_Def is my date field to output

Def_Year is the year

grid_code is the julian date

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi aurelies 

Can you share a screenshot of your data (the two fields involved?)

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Aurelie Shapiro ,

This would be the way you could use Arcade to get the date:

// input data from feature attributes
var year_value = $feature.Def_Year;
var julian_day = $feature.grid_code;

var year_date = Date(year_value, 0, 1);  // create date using first day of year
var final_date = DateAdd(year_date, julian_day, 'days');  // add the julian days
return final_date;‍‍‍‍‍‍‍
AurelieShapiro
Frequent Contributor

it worked! genius!!!

XanderBakker
Esri Esteemed Contributor

Hi aurelies , 

I'm glad it works now. Indeed in some case it would have required casting the text to a value. Which solution did you finally use? Python or Arcade?

Can you mark the post with the correct answer so that others can find the answer more easily?

0 Kudos
vdsri55
New Contributor

Can you please share same code in pyspak.

0 Kudos