February 29 2012

While on an 11g BPEL implementation, I had a fairly simple request to convert a date format from Julian to calendar.  I shrugged off the request as simple, and thought it shouldn't take more than a few minutes.  I was entertained by the fact that you can convert a date to Julian, but nothing was provided, unless I missed it, to convert a date from Julian!

Not that Julian is used very often, but when it is, most of the time it needs to be converted to calendar date for better recognition.

I did a search and found some complex solutions.  Some of the solutions involved functions and java code and some didn't even warrant an entire read through.  In either case, I just needed something quick and dirty, not necessarily to be re-used in multiple places.

Here is what I came up with!

XSLT - Julian to Calendar

A quick breakdown of my thought process:

1. Use the year portion of the Julian date to create a date object as January 1st.

2. Pull out the days portion of the Julian date, (subtract 1 - the date is already on the 1st) and create a duration string (ie. 'P125D')

3. Add the duration to the January 1st date created.

4. Format as necessary

The final product:

<xsl:value-of select='xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(concat(substring(/julianDt,0.0,5.0),"-01-01"), concat("P",(number(substring(/julianDt,5.0))-1),"D")), "[Y0001]-[M01]-[D01]")'/>

Hope this saves someone the time that it took me to finally figure it out!

About the Author

Kevin King

Kevin has over 12 years experience in enterprise scale implementations. Kevin is very experienced in architecting, modeling and developing solutions across many systems, internal and external.  These systems include ICS, DBCS, Weblogic domains, databases, EBS (cloud and on-prem), Java Web Services, SAP, and numerous Java APIs. Kevin is a hard-working, efficient technical resource, with excellent communication and planning skills.

Join the Conversation

July 18, 2013

Hey , I am looking for conversion of Date to Julian Format..Could you help me out in this.

October 16, 2014

Thanks Kevin, you definitely saved some of my time!

Enter your first name. It will only be used to display with your comment.
Enter your email. This will be used to validate you as a real user but will NOT be displayed with the comment.