Page 1 of 1

Convert Normal Date Into Julian Date

Posted: Fri Feb 19, 2016 1:10 am
by dbdecoy
Can anyone help me in converting normal date into Julian Date.

For eg: if we input 20160219 my output will be 116050(CYYDDD) format.

I have code for the reverse conversion (From Julian to Normal Date)

Code: Select all

OCONV(ICONV(Arg1 + 1900000, "D4-"), "D4-YMD[4,2,2]")
But not able to find a solution for converting other way round

Posted: Fri Feb 19, 2016 8:08 am
by chulett
Warning (pet peeve alert) but that is not a Julian date, which may explain your difficulty in finding the proper solution. From the docs:
A Julian day specifies the date as the number of days from 4713 BCE January 1, 12:00 hours (noon) GMT
What you are looking is called an ordinal date - the two digit year followed by the day number within that year. And the format string parallel function use to specify that is %ddd for "day of year".

That should get you on the right track.

Posted: Fri Feb 19, 2016 8:09 am
by Thomas.B
There is a forum dedicated to DataStage Server >Here<.
Perhaps you will have more answers there.

Edit : Damn, craig is fast !

Posted: Fri Feb 19, 2016 8:10 am
by chulett
And crap, just like that not the answer you are looking for. Didn't notice you posted Server code in the PX forum, let's get you over into the right one and see how we can approach this with our old friends the 'Conv Brothers'. :wink:

Posted: Fri Feb 19, 2016 8:12 am
by chulett
Thanks Thomas, moved it. Unfortunately, right off the top of my head I don't have an answer and don't have the proper time to research. I wonder if Ray's freely available date routines do that kind of conversion?

Posted: Fri Feb 19, 2016 8:55 am
by qt_ky
I once worked in an AS/400 shop that also incorrectly referred to these as Julian dates every day. Coincidentally, the date conversion code to get the day number of the year is J...

You could try something like this code below (where in this example, Date() represents today's internal date; modify as needed). Of course you would need to do the if then else logic to determine the first digit for the century.

Code: Select all

'1' : Oconv(Date(), 'DY[2]') : Oconv(Date(), 'DJ[3]')

Posted: Fri Feb 19, 2016 9:35 am
by chulett
Ah yes, I recall that now but funny it didn't come up in my quickie search of the Server pdf. Further perpetuating the myth of the Julian date! And one of the Mainframe folks here gave me a "Perpetual Julian Date" calendar just because they knew it would irk me. :wink:

And both of you guys need a "2" on the front, not a "1".

Posted: Fri Feb 19, 2016 1:34 pm
by qt_ky
That's funny.

Where I found the code was in the BASIC Reference Guide pdf (section: Correlative and Conversion Codes / Date Conversion): J Requests only the day number within the year (1 through 366). Notice that "Julian" is not part of the description...

From what I recall, the folks I worked with used century 0 to denote the 1900's and 1 to denote the 2000's. Using that logic, a 2 would denote the 2100's, so maybe it varies.

Posted: Fri Feb 19, 2016 2:38 pm
by chulett
Ah... that could be. Use whatever Century value is appropriate in your shop based on the incoming date.

Posted: Fri Feb 19, 2016 2:56 pm
by qt_ky
Just don't plan on supporting dates from the 1800's or earlier! :lol:

Posted: Sun Feb 21, 2016 3:59 pm
by ray.wurlod
Try

Code: Select all

Oconv(Iconv(InLink.TheDate, "DYMD"), "DYJ['1',2,3]" : @VM : "MCN")
You may like to finagle the century indicator based on the second character of the date string.

Code: Select all

InLink.TheDate[2,1] + 1 : Oconv(Iconv(InLink.TheDate, "DYMD"), "DYJ[2,3]" : @VM : "MCN")

Posted: Sun Feb 21, 2016 10:58 pm
by dbdecoy
Thanks for all the replies.Below code is working as per my requirement

Code: Select all

'1' : Oconv(Date(), 'DY[2]') : Oconv(Date(), 'DJ[3]')

Posted: Sun Feb 21, 2016 11:02 pm
by ray.wurlod
It is, but it's neither maximally efficient nor maximally flexible.