Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
dipanjan93
Contributor
Contributor

How to get Week Start Date in tMap?

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)

Labels (3)
3 Replies
Anonymous
Not applicable

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

dipanjan93
Contributor
Contributor
Author

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 -

0693p000008vmNBAAY.jpg Can we do anything here? Or is there any other way to handle this scenario?

Anonymous
Not applicable

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;

0693p000008vmV5AAI.png