Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a requirement where I need to get the Start Date of the week (currently in iteration ).
For example -
If the current iteration date is "2020-07-21" then Start Date of the week should be "2020-07-19" (basically needs to be a Sunday and should be in string format only)
Hi
No a built-in function available for getting the start date of a week. You can create a user routine and add this function
public static String getFirstDayOfWeek(String date) {
LocalDate assigned_date =LocalDate.parse(date);
return (assigned_date.with(previousOrSame(SUNDAY))).toString();
}
and then call this routine function on tJavaRow or tMap to get the start date of a week based on the given date. For example, on a tJavaRow:
output_row.startDate=RoutineName.getFirstDayOfWeek(input_row.given_date_column);
Take a look at this KB article to learn how to create a user routine.
https://community.talend.com/s/article/Create-a-user-routine-and-call-it-in-a-Job-0hHmU
Regards
Shong
Hi @shong,
Thanks for the solution!
But in routines seems like LocalDate can't be resolved to a type. Please find the screenshot below for details -
Can we do anything here? Or is there any other way to handle this scenario?
You need to import these class in the import section of routine.
import java.time.LocalDate;
import static java.time.DayOfWeek.SUNDAY;
import static java.time.temporal.TemporalAdjusters.previousOrSame;