End of Week Calculation
ngoda
Registered Posts: 2 ✭
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?
Tagged:
Best Answer
-
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
Answers
-
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)