How to achieve date

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
somu_june
Premium Member
Premium Member
Posts: 439
Joined: Wed Sep 14, 2005 9:28 am
Location: 36p,reading road

How to achieve date

Post by somu_june »

Hi,

I have a requirement like this I want to minus -1 day from the date .
For Ex. If I have date 99991231, I want to have 99991231-1 i.e 99991230.
how to achieve this. please help me




Thanks,
Somaraju
somaraju
rino
Participant
Posts: 1
Joined: Wed Sep 14, 2005 6:00 am
Location: Dubai

Post by rino »

Hi ,
U can solve such a requirment by converting the Input Date to Julian and subract one from the result

DateFromJulianDay(JulianDayFromDate(Input_date) -1)
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Somu

Try DateFromDaysSince Function. This functions adds an integer to the baseline date and returns date.

Regards
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
somu_june
Premium Member
Premium Member
Posts: 439
Joined: Wed Sep 14, 2005 9:28 am
Location: 36p,reading road

Post by somu_june »

Hi Rino,


sorry my requirement is not only for 9991231 and I have dates othr than that 19980204. I want to subtract 1 from these dates.




Thanks,
Somaraju
somaraju
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Read the response again. It IS a solution to your question.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
somu_june
Premium Member
Premium Member
Posts: 439
Joined: Wed Sep 14, 2005 9:28 am
Location: 36p,reading road

Post by somu_june »

Hi ray,

Thanks for reply. My requirement is I have a date with sql type char '19800412' and I want to minus one from this so I have to get '19800411' with sql type char. When I used DateFromDaysSince function.I getting an error since my requirement is with char sql type I tried like this in transformer I gave (DSLink.Validfromdate-'01') Iam getting an output as 1.99707e how to get my output as 19970701 please help me


Thanks,
Somaraju
somaraju
Raog
Participant
Posts: 8
Joined: Thu Oct 13, 2005 8:53 am

Conver to date and use Function

Post by Raog »

Hi SomaRaj,

First you have to convert char date to date data type then use DateFromDaysSince, U will get the result.

Ex:

DateFromDaysSince(-1, StringToDate("YourdateValue","%yyyy%mm%dd"))

Rgds,
Rao.


somu_june wrote:Hi ray,

Thanks for reply. My requirement is I have a date with sql type char '19800412' and I want to minus one from this so I have to get '19800411' with sql type char. When I used DateFromDaysSince function.I getting an error since my requirement is with char sql type I tried like this in transformer I gave (DSLink.Validfromdate-'01') Iam getting an output as 1.99707e how to get my output as 19970701 please help me


Thanks,
Somaraju
somu_june
Premium Member
Premium Member
Posts: 439
Joined: Wed Sep 14, 2005 9:28 am
Location: 36p,reading road

Re: Conver to date and use Function

Post by somu_june »

Hi Rao,

Iam getting an error like this when I used your logic


APT_CombinedOperatorController,0: Caught exception from runLocally(): APT_ParseError: Parsing parameters "**********" for conversion "date=date_from_days_since[**********](int32)": APT_Conversion_Date_DaysSince: Invalid Date [**********] used for date_from_days_since type conversion.

datefromdayssince is taking int32 as input how to achieve in my case.


Thanks,
Somaraju
somaraju
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Somu

Your Input is Char and Output is Char again. So you need to follow the steps

1. Convert Chat to Date using StringToDate Function
2. Use DateFromDaysSince Function to the result of Step 1 to Substract 1 day from the result.
3. Convert Back your date result to Chat type again using DateToString function.

Regards
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Slightly differently-named functions if you prefer to use Modify stages.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
somu_june
Premium Member
Premium Member
Posts: 439
Joined: Wed Sep 14, 2005 9:28 am
Location: 36p,reading road

Post by somu_june »

Hi Rasi,

I followed the steps you said but Iam getting the same error as I mentioned above post. I think this error is because of the function datefromdayssince.I think it will take only int(32) value or Iam making a mistake in conversion that is (%yyyy%mm%dd). Correct me if Iam wrong

DateToString(DateFromDaysSince(-1,StringToDate("Frm_Src.ValidFromDate","%yyyy%mm%dd")))


Thanks,
Somaraju
somaraju
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Somu

I had test with your code by substuting the input to hard coded value
DateToString(DateFromDaysSince(-1,StringToDate("20060726","%yyyy%mm%dd")))

I am getting the result = 2006-07-25 which is what you would expect. Check whether your input is correct. You can cut and paste the above code in your job to see whether it gives you the correct result
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
ameyvaidya
Charter Member
Charter Member
Posts: 166
Joined: Wed Mar 16, 2005 6:52 am
Location: Mumbai, India

Re: Conver to date and use Function

Post by ameyvaidya »

somu_june wrote:Hi Rao,

Iam getting an error like this when I used your logic


APT_CombinedOperatorController,0: Caught exception from runLocally(): APT_ParseError: Parsing parameters "**********" for conversion "date=date_from_days_since[**********](int32)": APT_Conversion_Date_DaysSince: Invalid Date [**********] used for date_from_days_since type conversion.

datefromdayssince is taking int32 as input how to achieve in my case.


Thanks,
Somaraju
This happens when the StringToDate fails to parse a date using the provided pattern.

To test why,

In the transformer, split this step into 2 seperate stage variable derivations:
1. ConvertedDate(DATE)<-- StringToDate(<IN.Date>,"%yyyy%mm%dd")
2. and the subtracted value using If isValid(ConvertedDate) then Subtract Value else 0.

Add another output link to the transformer that writes to a reject sequential file(Or a peek stage.. but I prefer Sequential Files) to capture the rows and values for which this conversion fails.


IHTH
Amey Vaidya<i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
somu_june
Premium Member
Premium Member
Posts: 439
Joined: Wed Sep 14, 2005 9:28 am
Location: 36p,reading road

Re: Conver to date and use Function

Post by somu_june »

Hi,

Thanks for every one. My problem was solved why Iam getting that error is my output is char(8 and when I used rasi steps I got my output as 2006-07-26 but I want as 20060726 so I coded like this to achieve my target


DateToString(DateFromDaysSince(-1,StringToDate(Dslink.Validfromdate,"%yyyy%mm%dd")),"%yyy%mm%dd")


Thanks,
Somaraju
somaraju
Post Reply