Discover all of the brand-new features and improvements to existing capabilities in the Dataiku 11.3 updateLET'S GO

End of Week Calculation

Solved!
ngoda
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? 

0 Kudos
1 Solution
CatalinaS
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

 

View solution in original post

0 Kudos
2 Replies
CatalinaS
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

 

0 Kudos
ngoda
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)