Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a date column in the format "DDMMMYYYY" I need to get the previous date,there is no specific function available in the tMap for subtracting a no of days from a date?
I got the answer,if anyone else is wondering how to do it.
If you have Java 8 &above you can use this routine
Input Date Format should be 'YYYY-MM-dd'
and date column should be passed as a string,you would also get the output as a string
package routines;
import java.time.*;
/*
* user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
* it must be before the "{talendTypes}" key.
*
* 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
* long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
* Short
*
* 3. {Category} define a category for the Function. it is required. its value is user-defined .
*
* 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]
*
* <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
* Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
* added. you can have many parameters for the Function.
*
* 5. {example} gives a example for the Function. it is optional.
*/
public class PreviousDate {
/**
* helloExample: not return value, only print "hello" + message.
*
*
* {talendTypes} String
*
* {Category} User Defined
*
* {param} string("world") input: The string need to be printed.
*
* {example} helloExemple("world") # hello world !.
*/
public static String GetSundayDate(String date) {
LocalDate date1 = LocalDate.parse(date) ;
LocalDate returnvalue = date1.minusDays(1);
String r=(returnvalue.toString());
return r;
}
}
There is a built-in function TalendDate.addDate(), you can find more information about this function in Repository-->Code--Routine>System-->TalendDate, try it!
Regards
Shong