2 Replies Latest reply: Jul 4, 2017 10:53 PM by Jo Tedesco RSS

    Change date to last friday?

    Annalisa Caradonna

      Hi,

      I'm developing an app and I need to do this customization:

       

      for every record:

       

      1) if date (in format YYYYMMDD) is a friday, no need change.

       

      2) if is not a friday, need to change to last friday. (for example, today 20170313 has to change in 20170310).

       

       

      I'm using num and weekday to extract the friday's , but I dont know how to continue.

       

      Any help?

        • Re: Change date to last friday?
          Annalisa Caradonna

          i have done this: 

          if(num(WeekDay( [Data di riferimento]) =0) ,[Data di riferimento] -3,
          if(num(WeekDay( [Data di riferimento]) =1),[Data di riferimento] -4,
          if(num(WeekDay( [Data di riferimento]) =2) ,[Data di riferimento] -5,
          if(num(WeekDay( [Data di riferimento]) =3),[Data di riferimento] -6,
          if(num(WeekDay( [Data di riferimento]) =4) ,[Data di riferimento],
          if(num(WeekDay( [Data di riferimento]) =5),[Data di riferimento] -1,
          if(num(WeekDay( [Data di riferimento]) =6),[Data di riferimento]-2,

           

          is there another procedure more dynamic?

            • Re: Change date to last friday?
              Jo Tedesco

              not an answer to your question - but this helped me !  I was trying to ensure that on a Friday we displayed the values for the following Monday - the SQL call was only a maximum of 4 days!

               

              Thank you

               

              Jo

              if(num(WeekDay(Today())) = 1,  num(WeekDay(Today())) +2,   

                  if(num(WeekDay(Today())) = 2,  num(WeekDay(Today())) +3    ,   

                  if(num(WeekDay(Today())) = 3,  num(WeekDay(Today())) +4 ,   

                  if(num(WeekDay(Today())) = 4,  num(WeekDay(Today())) +5    ,   

                  if(num(WeekDay(Today())) = 5,  num(WeekDay(Today())) +3   

                  )))))as DaysOfInt,