2 Replies Latest reply on Aug 4, 2017 6:17 AM by fawad001

    How to count the week End Day ?

    fawad001

      Hello,

      My scenario is to set the week start and end day by clicking a single button, so how would I calculate the days week start date and week end date?

       

      for the week starting and ending date,  I am using...

      For Week End Date : $WeekEndDate = Get ( CurrentDate ) + (7 - DayOfWeek ( Get ( CurrentDate ) ) ) + 1

      For Week Start Date:$WeekStartDate = $WeekEndDate - 6

       

      These formulae are working fine on the following days "From Monday to Saturday" but when I click on Sunday it jumps to the next week days which make sense because the dayofweek for sunday is "1" but my requirement is when user although click on Sunday, the start and end date must meet the current week dates.

       

      Looking forward to the answer.

       

      Thanks in advance.

        • 1. Re: How to count the week End Day ?
          Orlando

          Hi fawad001

           

          If you modify the $weekEndDate to check is the DayOfWeek value returned is a 1, you can then either just keep the date as is, as its the last day of the week, or minus the days as you were doing.

           

          Can also simplify the second part of the calculation by saying "- 8" instead of "-7 ... + 1", see below:

           

             $WeekEndDate = SelectedDate + If ( DayOfWeek ( SelectedDate ) = 1 ; 0 ; ( 8 - ( DayOfWeek ( SelectedDate )  ) ) )

           

          I hope this helps

          ! !

          -- Orlando

          • 2. Re: How to count the week End Day ?
            fawad001

            I just added this,

             

            If ( DayOfWeek ( Get ( CurrentDate ) )  ≠ 1 ;(Get ( CurrentDate ) + (7 - DayOfWeek ( Get ( CurrentDate ) ) ) + 1); Get ( CurrentDate ) )

             

            and it works.