Discussions

Expand all | Collapse all

Time Stamps

  • 1.  Time Stamps

    Posted 12-04-2018 21:51
    I have created a Time Stamp feature that I want to attach to a task. I have a Start check box that will start the timer and a Stop check box to end the time. My question is this: If I Start at 8:30 AM on Monday and Stop at 9:00 AM on Tuesday, is there a way to stop the internal timer for the hours from 5:00 PM Monday and 8:30 AM Tuesday, time that I was not in the office and would not apply to actual work spent on the task? Thanks in advance!


  • 2.  RE: Time Stamps

    Posted 12-04-2018 22:41
    The formula is brutal, but here is a gift.  it will be a formula numeric field type.

    The formula uses fields called [Status Start] and [Status End] which are date/time field types. 



    var timeofday DayStartTime = ToTimeOfDay("8:30 am");
    var timeofday DayEndTime = ToTimeOfDay("5:00 pm");

    var DateTime StartDateTime = Max([Status Start], ToTimestamp(ToDate([Status Start]), $DayStartTime));
     
    var DateTime EndDateTimeTesting = If(IsNull([Status End]), Now() ,[Status End]);

    var DateTime EndDateTime = Min($EndDateTimeTesting, ToTimestamp(ToDate($EndDateTimeTesting), $DayEndTime));

    var Number WeekDayDays = WeekdaySub(ToDate($EndDateTime), ToDate($StartDateTime)) + 1; //(we count each day as a full workday) 

    var number HoursBeforeStartEndAdjustment  = $WeekDayDays * ToHours($DayEndTime - $DayStartTime);

    var datetime StartDateTimeBounded = 
      If(ToTimeOfDay($StartDateTime) < $DayStartTime, ToTimestamp(ToDate($StartDateTime), $DayStartTime), $StartDateTime);

    var datetime EndDateTimeBounded = 
    If(ToTimeOfDay($EndDateTime) > $DayEndTime, ToTimestamp(ToDate($EndDateTime), $DayEndTime), $EndDateTime);

    Max(0,
    Round($HoursBeforeStartEndAdjustment 
    - Max(0,ToHours(ToTimeOfDay($StartDateTimeBounded) - $DayStartTime)) 
    - Max(0,ToHours($DayEndTime - ToTimeOfDay($EndDateTimeBounded))),0.1))


  • 3.  RE: Time Stamps

    Posted 12-05-2018 14:39
    Awesome, thanks. Unsure where to put formula numeric field though...This is my layout thus far



  • 4.  RE: Time Stamps

    Posted 12-05-2018 14:40
    Just create a new field called [Duration Hours Worked] and put it on the form.


  • 5.  RE: Time Stamps

    Posted 12-05-2018 15:02
    Gotcha. One thing please...Max(0, of the formula has an error of "Expecting duration but finding number". Should it be Max(0,ToHours.......,0.1))  ?


  • 6.  RE: Time Stamps

    Posted 12-05-2018 15:04
    please post the complete formula and the complete error.


  • 7.  RE: Time Stamps

    Posted 12-05-2018 15:08
    Sorry about that...This is the end of your formula

    Max(0,
    Round($HoursBeforeStartEndAdjustment 
    - Max(0,ToHours(ToTimeOfDay($StartDateTimeBounded) - $DayStartTime)) 
    - Max(0,ToHours($DayEndTime - ToTimeOfDay($EndDateTimeBounded))),0.1))

    Max(0, is highlighted in yellow and when I hover over it states "Expecting duration but finding number".

    It does not keep me from saving the field but I wasn't sure if it would stop the formula from working properly.


  • 8.  RE: Time Stamps

    Posted 12-05-2018 15:23
    The formula editor often produces false warnings.  If the formula saves then there is no error.


  • 9.  RE: Time Stamps

    Posted 12-05-2018 15:32
    I see. Thank you for your time.