cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
roli_
Level: Powered On

Splitting weeks falling into two months

I am currently using the following formula to find the first day of a week from a date picker:
DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)

(Weeks starts on a Monday in Europe).

 

This works fine, but I am struggling to find the first day of a week if you select  Wednesday 2 January 2019 for instance. My command would of course return Monday 31. December 2018, but I would like first day of the week in the same month to be reurned, Tuesday 1. January 2019.

 

Hope that makes sense and that someone can help me in the right direction.

 


Accepted Solutions
Community Support Team Rank
Community Support Team

Re: Splitting weeks falling into two months

Hi @roli_,

Based on the needs that you mentioned, I have made a test on my side, please take a try with the following workaround:7.JPG

Set the Text property of the Label control to following:

If(
    Year(DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)) = Year(DatePicker1.SelectedDate),
    DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero),
    Date(Year(DatePicker1.SelectedDate), 1, 1)
)

Please check the attached GIF screenshot for more details:

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

All Replies
Community Support Team Rank
Community Support Team

Re: Splitting weeks falling into two months

Hi @roli_,

Based on the needs that you mentioned, I have made a test on my side, please take a try with the following workaround:7.JPG

Set the Text property of the Label control to following:

If(
    Year(DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)) = Year(DatePicker1.SelectedDate),
    DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero),
    Date(Year(DatePicker1.SelectedDate), 1, 1)
)

Please check the attached GIF screenshot for more details:

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
roli_
Level: Powered On

Re: Splitting weeks falling into two months

 

Thanks Kris,


Your function only works for January as you are comparing year instead of months. I used your logic and changed to the Month function instead of the Year function. So the working function is:

If(
    Month(DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)) = Month(DatePicker1.SelectedDate),
    DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero),
    Date(Year(DatePicker1.SelectedDate), Month(DatePicker1.SelectedDate), 1)
)