Convert Normal Date Into Julian Date

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
dbdecoy
Premium Member
Premium Member
Posts: 17
Joined: Tue Jul 15, 2008 1:17 pm
Location: Hyderabad

Convert Normal Date Into Julian Date

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Thomas.B
Participant
Posts: 63
Joined: Thu Apr 09, 2015 6:40 am
Location: France - Nantes

Post by Thomas.B »

There is a forum dedicated to DataStage Server >Here<.
Perhaps you will have more answers there.

Edit : Damn, craig is fast !
Last edited by Thomas.B on Fri Feb 19, 2016 8:11 am, edited 1 time in total.
BI Consultant
DSXConsult
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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?
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post 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]')
Choose a job you love, and you will never have to work a day in your life. - Confucius
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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".
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post 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.
Choose a job you love, and you will never have to work a day in your life. - Confucius
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah... that could be. Use whatever Century value is appropriate in your shop based on the incoming date.
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Just don't plan on supporting dates from the 1800's or earlier! :lol:
Choose a job you love, and you will never have to work a day in your life. - Confucius
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dbdecoy
Premium Member
Premium Member
Posts: 17
Joined: Tue Jul 15, 2008 1:17 pm
Location: Hyderabad

Post 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]')
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It is, but it's neither maximally efficient nor maximally flexible.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply