Four Stars

quarterly and yearly details based on month and year

Hi,

 

i will receive a request from client. they will mention month and year like jun-18(string format) in text or excel file.

QUARTER - Based on jun-18 i have to get previous quarter i.e(mar-18) and previous year i.e(jun-17)

o/p

 jun-18 -- already given value from client, this also we need to show in output.

mar-18

jun-17

 

YEARLY - mostly Mar will the month, sometime they will use dec as year

a.PNGmostly yearly will be on marb.PNGsometime dec

for yearly also they will only give Jun-17. so only one value will be given from client as Jun-17. Based on the year yearly will be calculated on 

mar- 17  

mar-18

mar-19

mar-20 

example : 2 companies AAA, BBB

for company AAA. if we receive data from client as Jun-18 then we have to get yearly for 

 mar- 17  

mar-18

mar-19

mar-20 

same for company BBB. if we receive data from client as Jun-17 then we have to get yearly for 

Dec-17

dec-18

dec-19

dec-20

so we dont know whether march or dec is there in excl sheet. 

final output i want to get is

Jun-18

mar-18

jun-17

mar-17

mar18

mar-19

mar-20

if there is dec instead of mar then output

Jun-18

mar-18

jun-17

Dec-17

dec-18

dec-19

dec-20

6 REPLIES
Forteen Stars TRF
Forteen Stars

Re: quarterly and yearly details based on month and year

So, what's your question?

Do you want to know how to compute the expected date with the given format?

Have a look to this topic, it should help you for that.

https://community.talend.com/t5/Design-and-Development/How-to-change-code-from-tjava-to-globalmap-pu...


TRF
Four Stars

Re: quarterly and yearly details based on month and year

not exactly.

they have given a data jun-18

how to get the remaining values

jun-18 - based on this value

mar-18

jun-17

 

i dont know how to implement this in steps

a.PNGb.PNGc.PNG

Four Stars

Re: quarterly and yearly details based on month and year

TRF, can you help me to get the remaining output values.

Bcoz i have tried but not worked.

 

final o/p

 

Jun-18

mar-18

jun-17

mar-17

mar18

mar-19

mar-20

 

Six Stars

Re: quarterly and yearly details based on month and year

Hi Ravi,

 

your question is not so clear, what is your requirement, are you looking for time dimension ?

 

Thanks

Ashok

Four Stars

Re: quarterly and yearly details based on month and year

this is for quarterly and yearly report.

the code will calculate based on current month and year. And based month and year(example if this month is Jun-18) the below code will calculate as my wish.

 

Date lastDec =TalendDate.parseDate("yyyy-MM-dd", TalendDate.getDate("yyyy-MM-dd"));
System.out.println("param1: "+TalendDate.TO_CHAR(lastDec, "MMM-yy"));

Date prevYear1 = TalendDate.ADD_TO_DATE(lastDec, "YYYY", -1);
System.out.println("param3: "+TalendDate.TO_CHAR(prevYear1, "MMM-yy"));

Date prevYear = TalendDate.ADD_TO_DATE(lastDec, "MM", -3);
System.out.println("param2: "+TalendDate.TO_CHAR(prevYear, "MMM-yy"));

Date Year2 = TalendDate.ADD_TO_DATE(TalendDate.setDate(TalendDate.getCurrentDate(), 03, "MM"), "YYYY", 0);
System.out.println("para5: "+TalendDate.TO_CHAR(Year2, "MMM-yy"));

Date Year1 = TalendDate.ADD_TO_DATE(Year2, "YYYY", -1);
System.out.println("param4: "+TalendDate.TO_CHAR(Year1, "MMM-yy"));

Date Year3 = TalendDate.ADD_TO_DATE(Year2, "YYYY", +1);
System.out.println("param6: "+TalendDate.TO_CHAR(Year3, "MMM-yy"));

Date Year4 = TalendDate.ADD_TO_DATE(Year3, "YYYY", +1);
System.out.println("param7: "+TalendDate.TO_CHAR(Year4, "MMM-yy"));

 

But the problem is instead of getting current month and year using code. client will give Jun-18 as input either in text or excel file.

can you tell me. i dont know how to use that input in tjava code to get the remaining result .

 

so u can see my before post screen shot. in that i'm passing the input as context and getting printed as jun-18.

kindly tell me how to achieve the remaining result.

 

Jun-18

mar-18

jun-17

mar-17

mar18

mar-19

mar-20

Forteen Stars TRF
Forteen Stars

Re: quarterly and yearly details based on month and year

Does this helps?

Date startDate = TalendDate.parseDateLocale("MMM-yy", context.startDate, "EN");
System.out.println("startDate: " + startDate);

Date prev3months = TalendDate.ADD_TO_DATE(startDate, "MM", -3);
System.out.println("prev3months: "+TalendDate.TO_CHAR(prev3months, "MMM-yy"));

TRF