Calculate a project start date from the duration and project due date
Client specifies due date. based on certain criteria, a duration is assigned. How can the project start date be calculated from the due date and project duration? Thanks

  • Hey Rainer, Thank you for being willing to review and adjust this. I have replaced the script to match, but I now receive a numerical value of zero and I think this has to do with the " var workdays = 0; " line. Should this instead be my original calculation for my yielded workdays? See below: var workdays = 0;var workdays = (@Return to Office - @Days/Time Out of Office) / 86400000;When I swap the "var workdays" to not be zero it comes up with the 13 days calculation, but it is not removing the weekends from the sum. Thank you for your help here! I think after this calculation quest, I will need to get some night courses under my belt for the next round.
  • Hi Shane, it can't work cause that's the wrong code for your use case. The code needs a date = var dueDate and a number of days = var dur; but you have 2 dates. And the code returns a date, but you want to return a number of days.  You can try this one: var start = @Days/Time out of Office;var end = @Return to Office;var dur = moment(end).diff(moment(end),"days");var workdays = 0;for(var i = 0; i < dur; i++){    var day = moment(start).add(i,"days").isoWeekday();    if(day < 6){       workdays += 1;   }};workdays Try that code in a new calculation field. Rainer
  • Hello there Rainer,  I am looking to Chop & Screw your script to help us to calculate how many work days our employees are taking off on their vacation requests while excluding weekend days from the calculation. The issue is that I am a total hack at coding these calculations - DOH! Do you mind giving this a look over to let me know if I am just being a savage to your script?!?    Any help would be greatly appreciated! 
  •  you're right for the duration field. Didn't know that you use a real duration field :)  In the above example (Tieka) the duration is in a calculation field (as a number), many people use number fields for e.g. Project durations(if duration = Full days) . 
  • thanks :) it worked. :) but, a minor reminder: there is a bug, i think, in podio duration area. Days colums pretends as a hour. so, in formul i have to use /24.
  • Hi Admin-BK,change the linedate = duedatetodate = moment(dueDate)For the reverse scenario just change date.subtract(1, 'days')todate.add(1, 'days')I would also change subtractWeekdaystoaddWeekdays - just to make it clear that this is an add-function (it's only naming, doesn't have an impact on the result) Rainer  
  • may ask a thing Rainer;   First of all, the code is not working for me, i couldnt find the problem.   and a second phase, what if i want to reverse scenario? Start Day + Duration must be calculate End day (date) using workdays (starts monday morning and ends Friday afternoon.) how can i? thanks.      
  • Hi Tieka, you have to make sure that your duration field is a number type calculation field. Then you can use the following code for calculating the StartDate. Create a new calculation field in the template editor with: var dueDate = @DueDate-FieldName; var dur = @Duration-FieldName; function subtractWeekdays(date, days) { date = dueDate; while (days > 1) { date = date.subtract(1, 'days'); if (date.isoWeekday() !== 6 && date.isoWeekday() !== 7) { days -= 1; } } return date; } var startDate = subtractWeekdays(moment(),dur); moment(starDate).toDate(); Than click onto the field icon (left from the name) and choose the options in the field settings. For the calc in your duration field: If that what you have written in your post is the whole code in the field the result is a text string and you can't calculate further like you want to do. You have to use another code for getting the number of duration weekdays. And how to get the number depends on your setup :-) Rainer rg@delos-consulting.com
  • Hello Rainer, I set up the duration field as a calc that assigns the duration based on project details. Eg. a project with 1-2tems items is assigned 10 weekdays, 3-4 items is assigned 15 workdays and so on. I am not sure how it works yet. if (Number of Items == '1-2') {Duration Category = '10 weekdays';} else if (Number of Items == '3-4') {Duration Category = '15 weekdays';} else if (Number of Items == '5-6') {Duration Category = '20 weekdays';} else if (Number of Items == '7+') {Duration Category = '30 weekdays';} else if (Number of Items == 'Rush') {Duration Category = '5 weekdays';} I want to calculate with workdays and the start date should be a date field. Thanks again.
10 of 11
This question is closed.