Page 1 of 1

How to achieve date

Posted: Tue Mar 07, 2006 9:32 pm
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

Posted: Tue Mar 07, 2006 10:17 pm
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)

Posted: Tue Mar 07, 2006 10:28 pm
by rasi
Somu

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

Regards

Posted: Wed Mar 08, 2006 7:55 am
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

Posted: Wed Mar 08, 2006 8:32 am
by ray.wurlod
Read the response again. It IS a solution to your question.

Posted: Wed Mar 08, 2006 2:55 pm
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

Conver to date and use Function

Posted: Wed Mar 08, 2006 3:43 pm
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

Re: Conver to date and use Function

Posted: Wed Mar 08, 2006 4:03 pm
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

Posted: Wed Mar 08, 2006 4:32 pm
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

Posted: Wed Mar 08, 2006 5:30 pm
by ray.wurlod
Slightly differently-named functions if you prefer to use Modify stages.

Posted: Wed Mar 08, 2006 8:02 pm
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

Posted: Wed Mar 08, 2006 9:07 pm
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

Re: Conver to date and use Function

Posted: Wed Mar 08, 2006 11:56 pm
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

Re: Conver to date and use Function

Posted: Thu Mar 09, 2006 2:34 pm
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