I need to calculate the difference between two dates in the transformer
stage.
x = end_date - start_date
But there is some considerations:
- I need the difference in days
For example: x = 2005-05-12 - 2005-30-12
then x = 25
- the end_date is 'YYYY-MM-DD'
For example: 2005-05-12
- the start_date is 'YYMMDD' like a integer
For example: 050512 but how like a integer then 50512 because the 0 it disappears.
I'm trying to use Iconv and Oconv but I'm need help.
Can any one help me?
Regards,
Fernando Martins
Iconv and Oconv
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 142
- Joined: Wed Mar 24, 2004 10:51 am
- Location: Brazil
Hello Fernando,
you only need the ICONV function here; converting the EndDate is easy, just a ICONV(EndDate,'D4-YMD') will do the trick. The StartDate is somewhat moe of a challenge, as the lengths vary. I think that ICONV(FMT(StartDate,"8'0'R"),"D4DMY") should work, but I don't have a DS instance to test it on. The EndDate-StartDate will give you the difference in days.
you only need the ICONV function here; converting the EndDate is easy, just a ICONV(EndDate,'D4-YMD') will do the trick. The StartDate is somewhat moe of a challenge, as the lengths vary. I think that ICONV(FMT(StartDate,"8'0'R"),"D4DMY") should work, but I don't have a DS instance to test it on. The EndDate-StartDate will give you the difference in days.
Last edited by ArndW on Thu Sep 01, 2005 2:17 pm, edited 1 time in total.
-
- Participant
- Posts: 28
- Joined: Fri Jul 29, 2005 3:51 pm
- Location: Arizona, USA
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Iconv() is an exceptionally clever function. For dates all it needs is the day month year ordering (and not even that if the date is ordered correctly for your locale).
Therefore an elegant solution is
Therefore an elegant solution is
Code: Select all
Iconv(EndDate, "DYMD") - Iconv(StartDate, "DYMD")
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.
Hi,ray.wurlod wrote:Iconv() is an exceptionally clever function. For dates all it needs is the day month year ordering (and not even that if the date is ordered correctly for your locale).
Therefore an elegant solution isCode: Select all
Iconv(EndDate, "DYMD") - Iconv(StartDate, "DYMD")
I agree with ruy.I had used this code in my jobs.