cancel
Showing results for 
Search instead for 
Did you mean: 

Yesterday's Date

Former Member
0 Kudos

Hi,

I need to access Yesterdays Date in Message Mapping.

How UDF will look llike?

This is performing arithmetic operations on System DAte.

Regards,

Akshay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

try using this simple udf

cache parameter : value


public String ystdate(Container container)
{
long oneDay = (long) 1000.0 * 60 * 60 * 24;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

java.util.Date today = new java.util.Date(System.currentTimeMillis());

java.util.Date yesterday = new java.util.Date(System.currentTimeMillis()-oneDay);

String b = dateFormat.format(yesterday);
return b;
}

Under imports in udf
specify java.util.*;java.text.*;

Mapping

ystdate(udf)--->target

Edited by: malini balasubramaniam on Sep 18, 2008 1:28 PM

Edited by: malini balasubramaniam on Sep 18, 2008 2:11 PM

Answers (3)

Answers (3)

Former Member
0 Kudos

Akshay,

Outline your UDF based on the following code, import the following packages java.text.SimpleDateFormat;java.util.Date;java.util.Calendar:-


Date add_date = new Date();	
Calendar curr_cal = Calendar.getInstance();
SimpleDateFormat formatter  = new SimpleDateFormat("yyMMdd");
//depends on the format you need

//Add specified number of days
curr_cal.add(Calendar.DATE, Integer.parseInt(add_num));

//Get the new date from the Calendar object
add_date = curr_cal.getTime();

//Format date as per output required
String result = formatter.format(add_date);

Thanks,

Anand

former_member183906
Active Contributor
0 Kudos

You can do this by using CurrentDate function and implementing the logic through a udf, with one string input parameter. The input of such UDF is currentDate function. Here's what the code would look like:

PS: You need to import java.text.* and java.util.* for this udf.

Regards and happy new year!

int diaSemana = 0;

try{

DateFormat format = new SimpleDateFormat("yyyy/MM/dd");

Calendar calendar = Calendar.getInstance();

Date date = format.parse(a);

calendar.setTime(date);

diaSemana = calendar.get(Calendar.DAY_OF_WEEK); /weekday/

if (diaSemana == 7) {

calendar.add(Calendar.DATE, 2);

date = calendar.getTime();

return new SimpleDateFormat("MM/dd/yyyy").format(date);

}

else {

calendar.add(Calendar.DATE, 1);

date = calendar.getTime();

return new SimpleDateFormat("MM/dd/yyyy").format(date);

}

} catch (Exception e){ }

return "";

OR

1. Use a concat with the following input parameters:

1a)

currentDate (Target Format EEE)

the result should be the current weekday (e.g. Mi for Wednesday here in Germany, maybe you got other values for another system installation)

after the currentDate do FixValues and create a mapping table for the yesterday (e.g. Mi --> Do).

1b)

currentDate (Target Format MMyyyy)

2. The result of the concat should be the next weekday in letters concatenated with month and year in digits. Now use the DateTrans function with the following parameters:

2a) Source Date: EEEMMyyyy

2b) Target Date: for example yyyyMMdd --> this should be the correct day

former_member192295
Active Contributor
0 Kudos

Hi,

Under Mapping window choose date function under select Before data function, it will work or develop simple UDF function sue system date -1 logic.