I want to Calculate Timespent automatically, Is there a way to do this without any code

Comments

11 comments

  • Rainer Grabowski (FVM)

    Hi Jayraj,

    yes, there is a way. But you have to create a calculation field for that and to write (or at least copy) some simple Javascript code. How this code looks like, depends on your setup. Are the time sheets connected via a relationship field to Deliverables? Would like to calculate spent time in Timesheets only or do you want to sum all time spnet for one Deliverable in the Deliverables App? Btw: You can't calculate the time spent if start and end date are in the same date field, you need two date fields for that, one for start and one for end.

    Would be helpful If you could share some more details of your app setup and your needs.

    Rainer
    rg@delos-consulting.com

    0
    Comment actions Permalink
  • Jayraj Berde

    Hi Rainer,

    Yes the Start Date and End Date are two different fields with time

    • Based on the state date time and the end date time I want to calculate how long it took to complete the deliverable which should give me the duration

    • Even if its in the deliverables app it is fine, as then I can shoot that calculation into the timesheet app for further calculation.

    • Can you guide me here please.

    Regards,
    Jayraj

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hello Jayraj,

    you can calculate the time spent in the time Timesheet app and then sum the duration of all timesheets for a deliverable in the deliverables app. Create a calculation field in the Timesheet App and call it eg. "TimeSpent":

    var start = moment(@startDate);
    var end = moment(@endDate);
    var unit = "days";
    end.diff(start, unit) 
    

    You can change the unit as you like it: e.g. to "hours" or "minutes". That counts calender days. If you want workdays only , you'll find a solution here, where I've posted a code for calculating the duration in business days https://help.podio.com/hc/communities/public/questions/202828487-Calculating-workdays?locale=en-us
    You can copy it, only ypur date field names into the variables at the beginning.

    For summing all Time spent entries for one deliverable create a calculation field in the Deliverables app with:

    @sum of TimeSpent
    

    For that the Time spent app must be related to the deliverables app via a relationship field (I assume that you already have that relationship field in the Timesheet app).

    Rainer

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Jayraj

    that IS the exact JavaScript Code. You only have to put in the field names of YOUR date fields (type @fieldname and select the token from the list which opens after typing @ The more you type the shorter the list becomes) and than in the calc field in Deliverables after @sum of the fieldname of the calc field in Time Spent which calculates the duration. The code for calculating workdays you can also copy and paste as it is (only put in your date field names), The text behind // are only comments, you can take altogether into your calculation field.

    Rainer
    rg@delos-consulting.com

    0
    Comment actions Permalink
  • Jayraj Berde

    Hi Rainer,

    I tried it, the result I am getting is 0.

    My Start Date is 14/04/2015 4:00 PM
    My End Date is 14/04/2015 7:00 PM

    the result is coming as 0. I need it to show 3.0 or 03.00 or 03:00

    Any suggestions, we maybe close

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Please copy your script and paste it here in the comments

    0
    Comment actions Permalink
  • Jayraj Berde

    Hi Rainer,

    var start = moment(@Deliverable Start Date);
    var end = moment(@Deliverable End Date);
    var unit = "hours";
    end.diff(end,unit)

    0
    Comment actions Permalink
  • Jayraj Berde

    Tried this one earlier too:

    var start = moment(@Deliverable Start Date);
    var end = moment(@Deliverable End Date);
    var unit = "days";
    end.diff(end,unit)

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Your last line is wrong. With that calculate the difference between "end" and "end" - and that should 0 :)

    end.diff(start,unit)
    

    should work.
    Rainer

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    NB: The result of this calculation is an integer. That means for your example
    My Start Date is 14/04/2015 4:00 PM
    My End Date is 14/04/2015 7:00 PM

    • in case of using "Days" as unit result = 0 (exact result is 0.13 days)
    • in case of using "hours" as unit result = 3 (exact result = 3.00 hours)

    But if end date is 7:30 you also will get the result 3 (hours; exact result would 3.5 hours).
    So if you want the exact result with decimals take a the next smaller unit and devide it like
    var unit = "minutes"
    end.diff(start,unit)/60 // result = 3,5 hours (for end date 7:30 PM)
    or
    var unit = "hours"
    end.diff(start, unit)/24 // result = 0.13 days

    Rainer

    0
    Comment actions Permalink
  • Jayraj Berde

    Hi Rainer,

    Thank you so very much, I have gone with the minutes scenario and I now have the right result. This will surely help. Thank you so very much once again.

    Regards,
    Jayraj

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk