julian date conversion

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
supernova2005
Participant
Posts: 37
Joined: Mon Jan 24, 2005 10:12 am

julian date conversion

Post by supernova2005 »

Hi everyone,

I need to convert a julian date with formate yyyyddd to regular date formate, for example,

if the input is 2005001, then the output is 01/01/2005. Does datastage have a built-in function to do that, otherwise I have to write my own logic, which is very complicated, because I have to consider leap years.

Your suggestions will be appreciated.

thanks.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

You need to use IConv and OConv.
amsh76
Charter Member
Charter Member
Posts: 118
Joined: Wed Mar 10, 2004 10:58 pm

Post by amsh76 »

Use ICONV to convert the Julian Date into DataStage internal format..and then use OCONV to convert into the format you want.

regards
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Can we move this topic to Server section rather than FAQ.
T42
Participant
Posts: 499
Joined: Thu Nov 11, 2004 6:45 pm

Post by T42 »

For EE - there are already a few functions that converts to JulianDay and back to Date. All you need to do is convert the string into Date.
changming
Participant
Posts: 68
Joined: Wed Oct 13, 2004 3:35 am

use sub string function

Post by changming »

if the data is clean, i mean they are all valid date, the eastest way is to use sub string function. string[].
of course you can use iconv and oconv, but it will cost performance more.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Show us how you convert 001 to 01/01 and 059 to 02/28 and 060 to ... umm ... is it 02/29 or 03/01, using substring. :!:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

The code you require is as below

memYear = Arg1[1, 4]
memJJJ = Arg1[5, 3]

memDSDate = IConv(memYear : '-01-01', 'D-YMD[4,2,2]') - 1 + memJJJ
* -1 to check until last year Dec 31st

Ans = OConv(memDSDate, 'D/DMY[2,2,4]')


Stick it into a routine and reference it from your jobs.

There are other pre-built codes - such as YEAR.TAG - that does part of this functionality. Anyhow, this will be one call for your job.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Just remember after pressing the submit button. You can do it in simple way of using IConv(YYYYJJJ, 'DYJ') rather than the full routine and then follow it with your OConv.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

A couple of quick points...

On the substring issue, Ray meant using only the substring operator - which is what was implied by changming. All fine and dandy when rearranging 'normal' dates, but not appropriate for converting from Julian. :wink:

Also, you *can* edit your own posts, so rather than post a correction simply go back and fix it. You can do this even if it's been replied to, unlike deleting a post which can only be done if no-one has replied. FYI.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Thanks for the tip about changing own post.

PS - I did not try to prove substring theory. My intention, as you can see from the second post in this thread, was to provide a response to supernova2005's requirement.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah... sorry. Since you replied immediately after that using [] to hack up the input argument, I figured you were.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

No worries!!

Anyhow, as you had challenged, please see the simple (!?) code to perform the same WITHOUT IConv or OConv.


**** Beginning of Routine ****

* Ans = OConv(IConv(Arg1, 'DYJ'), 'D/DMY[2,2,4]')

memYYYY = Arg1[1, 4]

memDaysRemaining = Arg1[5, 3]

If memDaysRemaining = 0 Then
memYYYY = memYYYY - 1
memMM = 12
memDD = 31
End

If Mod(memYYYY, 4) = 0 And Mod(memYYYY, 400) <> 0 Then
memLeapDay = 1
End
Else
memLeapDay = 0
End

memMonthDays<1> = 31
memMonthDays<2>= 28 + memLeapDay
memMonthDays<3>= 31
memMonthDays<4>= 30
memMonthDays<5>= 31
memMonthDays<6>= 30
memMonthDays<7>= 31
memMonthDays<8>= 31
memMonthDays<9>= 30
memMonthDays<10>= 30
memMonthDays<11>= 30
memMonthDays<12>= 30



For memThatMonth = 1 To 12 Step 1
If memDaysRemaining > 0 And memDaysRemaining <= memMonthDays<memThatMonth> Then
memMM = memThatMonth
memDD = memDaysRemaining - 0
memDaysRemaining = 0
Exit
End
Else
memDaysRemaining = memDaysRemaining - memMonthDays<memThatMonth>
End
Next memThatMonth

If memDaysRemaining > 0 Then
memMM = 99
memDD = 99
End

Ans = Fmt(memDD, "2'0'R") : '/' : Fmt(memMM, "2'0'R") : '/' : Fmt(memYYYY, "4'0'R")
***** End of Routine ****
Post Reply