cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for Date -7 days

Former Member
0 Kudos

Hi everyone

I am fairly new to Java and PI, and I have to create a UDF that takes the currentDate and subtracts 7 days. I was just wondering the best way to go about this with java?

Thank You

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

UDF Code as below ..

Calendar now = Calendar.getInstance();
now.add(Calendar.DATE, -7);
String subtractSevenDays = new SimpleDateFormat("yyyy/MM/dd").format(now.getTime());
return subtractSevenDays;

// Dont forget below import statements

import java.text.SimpleDateFormat;

import java.util.Calendar;

Map it to target field.

Note: You can choose any pattern in the above SimpleDateFormat argument.

Currently the output will be ex: 2011/04/01

Edited by: Baskar Gopal on Apr 8, 2011 10:56 AM

Answers (4)

Answers (4)

Former Member
0 Kudos

Ok Sorry I missed some of that last post, It works

Thank you everyone

Former Member
0 Kudos

I still seem to be getting errors?

Former Member
0 Kudos

Have a look into this blog and see case 5..

/people/sarvesh.singh3/blog/2009/02/13/yes-it-is-possible-with-datetrans-function

Former Member
0 Kudos

HI,

you can use the grafical Function "current date" and "DateBefore" or "DateAfter".