cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF for Date?

umesh_badveli
Participant
0 Kudos

Hi all,

I have a requirement in one field where we need to send date but here I need logic for date field

If interface running is present month then output of the field is previous month last date

ex: if run date 2015-03-07 then output is 2015-02-29

please help on this requirement and provide UDF to achieve this.

Regards

Umesh

Accepted Solutions (1)

Accepted Solutions (1)

sahithi_moparthi
Contributor
0 Kudos

Hi,

Please use below UDF

Calendar aCalendar = Calendar.getInstance();

// add -1 month to current month

aCalendar.add(Calendar.MONTH, -1);

// set actual maximum date of previous month

aCalendar.set(Calendar.DATE,     aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));

String strdate = null;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

if (aCalendar != null) {

strdate = sdf.format(aCalendar.getTime());

}

return strdate;

Don't forget to import java.text.SimpleDateFormat

umesh_badveli
Participant
0 Kudos

Hi Sahithi

Thanks for your reply

I have small doubt in that Code ,Code seems to be without argument I that case I we don't need argument right ?

without argument I am able to achieve that requirement.

Correct me if I am wrong .

Regards

Umesh

sahithi_moparthi
Contributor
0 Kudos

Hi,

Yes,It is without argument.If it is working as expected please mark the answer as correct and close the thread.

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

Hi Umesh,

That logic can't be done in a standard function, a you will need to do an own UDF. This thread could help you hhttp://stackoverflow.com/questions/10828398/how-to-get-the-first-date-and-last-date-of-the-previous-...

The same question in a PI thread: https://scn.sap.com/thread/3564604

Regards