Survey banner
Share your feedback on the Dataiku documentation with this 5 min survey. Thanks!

# End of Week Calculation

Solved! Level 1
###### End of Week Calculation

Hi,

I have a date column in my data and wants to increment the date (i.e. Monday, 7/11/2022) to the end of the week (i.e. Saturday,  12/11/2022 ). I saw the other the post for month end calculation and it worked perfectly for my case but struggling to modify it to make end of the week.

How can I do that?

1 Solution Dataiker

Hi @ngoda,

This custom Python function calculates the end of the week (Saturday) based on the input date column line:

``````import datetime
from datetime import timedelta

def process(row):
current = datetime.datetime.strptime(row["line"],'%m/%d/%y')
start = current- timedelta(days=current.weekday())
end = start + timedelta(days=5)
row["EndWeek"]=end.strftime("%m/%d/%Y")
return row``````

2 Replies Dataiker

Hi @ngoda,

This custom Python function calculates the end of the week (Saturday) based on the input date column line:

``````import datetime
from datetime import timedelta

def process(row):
current = datetime.datetime.strptime(row["line"],'%m/%d/%y')
start = current- timedelta(days=current.weekday())
end = start + timedelta(days=5)
row["EndWeek"]=end.strftime("%m/%d/%Y")
return row`````` Level 1
Author

Thanks for the prompt response. I also figured how to do this using the DSS processor.

2 steps process

1. Calculate the difference in days between current day to Sunday. (Monday = 1 and Sunday is 7)

2. Then add that difference to the original date to get to the last day of the week (i.e. Saturday)  