Date to Julian
Moderators: chulett, rschirm, roy
Date to Julian
Hi - I am trying to convert a date to Julian format. The format I require is
105202.
1 represents 21st century
05 is current year
202 is the days in Julian format.
Is there a fn or routine is DS to achieve this. Thank you.
Kumar
105202.
1 represents 21st century
05 is current year
202 is the days in Julian format.
Is there a fn or routine is DS to achieve this. Thank you.
Kumar
Hello Kumar,
the functions ICONV and OCONV will do this for you. I will split the actions into several lines, but it can be done in one line. You are not looking for a "Julian Date" but a specific date format - be careful of using misleading terms.
1. ICONV({Date},'D4/YMD[4,2,2]') Convert your displayable date into DataStage internal format, I'm using "2005/04/31" type format here.
2. INT(OCONV({1},'DY4')/100)-20+1 Gets the Century number offset by 20
3. OCONV({1},'DY4')[3,2] Gets the last 2 digits of a 4 digit year
4. OCONV({1},'DJ') Get the days-running in current year.
the functions ICONV and OCONV will do this for you. I will split the actions into several lines, but it can be done in one line. You are not looking for a "Julian Date" but a specific date format - be careful of using misleading terms.
1. ICONV({Date},'D4/YMD[4,2,2]') Convert your displayable date into DataStage internal format, I'm using "2005/04/31" type format here.
2. INT(OCONV({1},'DY4')/100)-20+1 Gets the Century number offset by 20
3. OCONV({1},'DY4')[3,2] Gets the last 2 digits of a 4 digit year
4. OCONV({1},'DJ') Get the days-running in current year.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
Sainath,
I intentionally broke up the command into it's separate components so that Kumar could see what and how ICONV/OCONV work. With that information he can write the command to his wishes. I prefer this over giving the actual answer to the question - thus the longer and more complex method than actually needed. But, what would you write? I would do it with 1 ICONV and 2 OCONVs in one line.
I intentionally broke up the command into it's separate components so that Kumar could see what and how ICONV/OCONV work. With that information he can write the command to his wishes. I prefer this over giving the actual answer to the question - thus the longer and more complex method than actually needed. But, what would you write? I would do it with 1 ICONV and 2 OCONVs in one line.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
I completely agree with you.
As a Chinese proverb goes,
By-the-way, I may have solved it with one IConv and one OConv.
As a Chinese proverb goes,
Also it is good for people who really have the requirement to find the answer than those who only need it for an interview.Give a person a fish and you feed him for today. Teach him finishing and he will feed himself for lifetime.
By-the-way, I may have solved it with one IConv and one OConv.
-
- Participant
- Posts: 232
- Joined: Sat May 07, 2005 2:49 pm
- Location: USA
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Your requirement will cause problems if you have dates ten years apart crossing a millenium boundary (for example 1005-07-29 and 2005-07-29). The "century" will be 1 in each case (11th and 21st). Your result will be identical in each case.
Sit a man by a fire and he's warm just for a while. Set him on fire and he's warm for life.
Last edited by ray.wurlod on Sat Jul 23, 2005 5:24 pm, edited 2 times in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
I disagree. There is no mention of given year in the requirement. Just the fact that there's a date. The requirement for a two digit year is in the output. My point was that one digit for the "century" may not be enough, or that the restriction on dates properly handled needs to be documented among the technical (design) metadata.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
I too had the same scenario, when i raised the same issue, i got very lethargic answer, their whole business were not there bofore 100. so they are not ready to forcast beyond 1000 years for current project:oops:ray.wurlod wrote:Your requirement will cause problems if you have dates ten years apart crossing a millenium boundary (for example 1005-07-29 and 2005-07-29). The "century" will be 1 in each case (11th and 21st). Your result will be identical in each case.Sit a man by a fire and he's warm just for a while. Set him on fire and he's warm for life.
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
These date formats are commonly used, for example in Peoplesoft (oops, I mean Oracle), the format is yyyddd, where yyy is the number of years since 1900, and ddd is the day of the year. So today, August 2, 2005 is 105214.
For years before 1900, you are probably SOL.
Note that years before 2000 will result in a leading zero, that may disappear when the variable is evaluated in a numeric context.
So you have to be consistent, and be careful when doing comparisons:
String '098105' becomes number 98105, which becomes '98105' when converted back to a string, either implicitly or explicitly,
and '098105' != '98105'
For years before 1900, you are probably SOL.
Note that years before 2000 will result in a leading zero, that may disappear when the variable is evaluated in a numeric context.
So you have to be consistent, and be careful when doing comparisons:
String '098105' becomes number 98105, which becomes '98105' when converted back to a string, either implicitly or explicitly,
and '098105' != '98105'