85
Views
11
Comments
Calculate date without saturday and sunday
Question

Question:

  • start date - 14/12/2023
  • adddays - 3days
  • enddate - ???

Formula:

 start date + adddays = enddate


Actual output: 14/12/2023 + 3days = 19/12/2023
Appreciate if anyone can guide the method to calculate the enddate and avoid the weekend?????

Thank youuu


2023-05-23 04-55-55
Wasimkhan Syed Abuthahir

Hi JW L,

Please refer to this post. Hope this helps.

https://www.outsystems.com/forums/discussion/45772/how-to-add-days-to-date-excluding-weekends/


Regards,

Wasimkhan S

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

Consider using a Forge component that already implemented that logic for your:

https://www.outsystems.com/forge/component-overview/11440/working-days-reactive

Regards,

Daniel

2024-01-04 09-21-21
Venkatesaiya

Hi jwl , 
I done one logic and sample output is
 
I attched the OMl  file, please refer it.

Forum.oml
UserImage.jpg
JWLoo

Appreciate of your help. I have created the calculation client action but I'm facing the issue now which is I don't know how to loop the client action row by row based on different adddays but same start date in table. Do you know how to do this? If yes, please guide me~~~~


I'm able to calculate when adddays is 5. How about if I change the adddays to 3days and enddate should be 15/12/2023.


I put this client action in on change action of input startdate.
How to loop this client action to calculate the different SLA and same startDate in table above? 

2024-01-04 09-21-21
Venkatesaiya

Sure,
1. Set as function to used client Action.2. Used client action in Expression in your tableI hope its helpful.

2024-01-04 09-21-21
Venkatesaiya

The sample output is 
I attached the oml for your reference, kindly refer it

Forum.oml
UserImage.jpg
Himani Sharma

Hi @JW L  


Please consider the below mentioned code: 

var startDate = "9-DEC-2011";
startDate = new Date(startDate.replace(/-/g, "/"));
var endDate = "", noOfDaysToAdd = 13, count = 0;


while(count < noOfDaysToAdd){   
        endDate = new Date(startDate.setDate(startDate.getDate() + 1));    
        if(endDate.getDay() != 0 && endDate.getDay() != 6){       
                  //Date.getDay() gives weekday starting from 0(Sunday) to 6(Saturday)      
                  count++;    }}
alert(endDate);


OR

You can try with advance sql also -

Pass two parameters @MyDate ,@MyDays and define a structure of type Date and execute the below query

SELECT        DATEADD(d      
 , (@MyDays / 5) * 7          
+ (@MyDays % 5)         
 + (CASE WHEN ((@MyDays%5) + DATEPART(dw, @MyDate)) IN (1,7,8,9,10) THEN 2 ELSE 0 END)        , @MyDate) AS Date


Thanks 

Himani

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

You copied the javascript from this reply:

https://www.outsystems.com/forums/discussion/45772/how-to-add-days-to-date-excluding-weekends/#Post166785

and the SQL from this reply:

https://www.outsystems.com/forums/discussion/45772/how-to-add-days-to-date-excluding-weekends/#Post166785 

Better to just share the replies, instead of pretending it is your solution.

Furthermore, the discussion from which you copied this, was already shared on the first reply of this discussion, so totally unnecessary to share again.

Regards,

Daniel

UserImage.jpg
Himani Sharma

Hi 

I didn't provide a link because there were multiple suggestions, and my intention was to save time and help more directly. 

I shared the solution directly in the code instead of providing a link because I wanted to be specific and efficient in helping. Knowing that anyone can easily search and find the source if needed. 

Thanks 

Himani

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Given that exactly these 2 replies were marked as solution, there is no need to do that.

Furthermore, if you do, following the community guidelines, you could mention the source.


2022-07-03 17-24-08
Sourabh sharma

Hi @JW L ,

Did you get the solution? if not ! Here is the forge use this, logic is written there kindly go through that .

Demo - Try

Forge - Day calculation

Hope this will help you!

Kind regards

Sourabh Sharma

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.