# How to get date of start of the week based on date column

**URL:** <https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687>\
**Category:** KNIME Analytics Platform\
**Created:** [June 19, 2020, 1:50am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687 "2020-06-19T01:50:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sljw](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@sljw](https://forum.knime.com/u/sljw)\
**Post date:** [June 19, 2020, 1:50am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/1 "2020-06-19T01:50:17Z")

</div>

Hi,

I’m pretty new to Knime but I would like to find out how I can calculate the week commencing date based on a column of dates.

For example if my date is 19/6/2020 then the week commencing date (Mon-Sat) should be 15/6/2020.

Thanks!

---

<div class="post-metadata">

**Author:** ![webstar](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/w/a6a055/32.png) [@webstar](https://forum.knime.com/u/webstar)\
**Post date:** [June 19, 2020, 5:33am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/2 "2020-06-19T05:33:36Z")

</div>

What happens is the date is June 14 Sunday?  
Do you want the previous Mon June 8th - Sat June 13 ?  
or do you want the Mon-Sat which comes after which is June 15-June 19th?

---

<div class="post-metadata">

**Author:** ![andrejz](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/b19c9b/32.png) [@andrejz](https://forum.knime.com/u/andrejz)\
**Post date:** [June 19, 2020, 5:47am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/3 "2020-06-19T05:47:10Z")

</div>

Hi,

Try with the “Date&Time Extraction” node.  
From the date you can extraxt week number and then with “Groupby” node group by week and manual aggregation select minimum of the date column.  
Or you can extract day name an then filter mondays (or sundays)

---

<div class="post-metadata">

**Author:** ![webstar](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/w/a6a055/32.png) [@webstar](https://forum.knime.com/u/webstar)\
**Post date:** [June 19, 2020, 5:57am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/4 "2020-06-19T05:57:58Z")

</div>

Agree with above - I used the following seq. to get at your problem

1. create a date and time range fixed for 1 day
2. extract date and time fields to get day of week number and day of week name (really just need number)
3. Rule engine  
$Day of week (number)$ =1 =\> 1  
$Day of week (number)$ =2 =\> 0  
$Day of week (number)$ =3 =\> -1  
$Day of week (number)$ =4 =\> -2  
$Day of week (number)$ =5 =\> -3  
$Day of week (number)$ =6 =\> -4  
$Day of week (number)$ =7 =\> -5  
appending a new column called Start\_index
4. date& time shift: select numerical column start\_index with Granularity days  
**5) A second date time shift node with fixed number of days as 5**  
You always get Monday to Sat no matter what you put in . with Sunday you get the immediate Mon - Sat.

![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/4/147cdf11223a190acdb10706a984fa6b26453884.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/9/39abdf6d84ae7c6b14211b6dd36256719f77f0f0.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/0/5/0569a01671a35b3b3997b37cfa18b1bb83d9a5f6.png)

See complete flow here:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/d/6d1380ccf38f1c1881da02f9baad376fb353a522.png)

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [June 19, 2020, 6:19am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/5 "2020-06-19T06:19:39Z")

</div>

Could you upload your workflow here or even better to the KNIME hub?

[https://www.knime.com/blog/the-knime-hub-share-and-collaborate](https://www.knime.com/blog/the-knime-hub-share-and-collaborate)

---

<div class="post-metadata">

**Author:** ![webstar](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/w/a6a055/32.png) [@webstar](https://forum.knime.com/u/webstar)\
**Post date:** [June 19, 2020, 6:21am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/6 "2020-06-19T06:21:21Z")

</div>

yes [01\_Generate\_Fixed\_Time\_Intervalls\_x 1.knwf](https://forum.knime.com/uploads/short-url/3MQ74Ao3VgaTk8OZS6YStCpj1ye.knwf) (28.6 KB)

Was playing around with other joins here as I imagined what the solution was - but the flow at the bottom works to solve the problem

---

<div class="post-metadata">

**Author:** ![webstar](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/w/a6a055/32.png) [@webstar](https://forum.knime.com/u/webstar)\
**Post date:** [June 19, 2020, 6:23am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/7 "2020-06-19T06:23:23Z")

</div>

[mlauber71](https://forum.knime.com/u/mlauber71) let me know what you think?

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [June 23, 2020, 10:35am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/8 "2020-06-23T10:35:50Z")

</div>

Hi @webstar,

seems fine to me. And it was marked as Solution so guess it’s works fine for topic creator as well 😉

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 30, 2020, 10:35am UTC](https://forum.knime.com/t/how-to-get-date-of-start-of-the-week-based-on-date-column/24687/9 "2020-06-30T10:35:50Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
