Weekly Totaling of Time.

2»

Comments

  • webweb Member Posts: 102
    I now have "Total Time" as decimal datatype. But the values give me results like 12.97. I needed the result to be in time. I have been having problems in converting decimals to time.
    Any idea please?
    Thanks
  • Alex_ChowAlex_Chow Member Posts: 5,063
    How the heck is that possible?! :shock:

    How do you display 11am - 2pm?
  • SavatageSavatage Member Posts: 7,142
    I would've by now just given in to an easy answer and stated dividing.

    like take the .97 part w/ copystr or something, use some FORMAT's & EVLAUATES when needed & divide by 1.666 to give me the minutes. and throw it together in a text file vHour+':'+vMin

    Sometimes I don't have the patients myself :lol:
  • jlandeenjlandeen Member Posts: 524
    I've been playing around with Times, Durations & DateTimes in the last few days on manufacturing project...but I've found it all boils down to some really simple math.

    If you take a look at the documentation it shows that DURATION = DATETIME +/- DATETIME. But a variable of Duration Data Type is also synonymous with BigInt and stores time in milliseconds (1/1000th of a second).

    So what I've done is delcare 4 Variables:
    tmeStart (Time) - start time from user form
    tmeEnd (Time) - end time from user form
    durElapsed (Duration) - Duration datatype
    iElapsed (Big Integer) - to be used for calculations
    iRunTime (Integer) - Run Time for Journal line - in minutes
    

    I'm going to skip a lot of logic I had in my form that tested whether the user had populated Start Time/End Time, whether they were within tolerances, etc. Then to Calculat etime Run Time in Minutes I used:
    durElapsed := CREATEDATETIME(TODAY,tmeEnd) - CREATEDATETIME(TODAY,tmeStart);
    iElapsed := durElapsed;
    iRunTime := iElapsed/60000;
    

    Remember that you must subract the Start Time from the End time to get a positive duration.

    If you use iElapsed (or any other Big Integer) you can convert a duration to whatever you like using this conversion table:
    1 Second = 1000
    1 Minute = 60000 (or 60 * 1000)
    1 Hour = 3.6 Million (or 60 * 60 * 1000)
    1 Day = 86.4 Million (or 24 * 60 *60 * 1000)

    So if you divide iElapsed by the appropriate value above you can turn a duration into whatever you like (hours, mins, seconds, etc).
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • webweb Member Posts: 102
    durElapsed := CREATEDATETIME(TODAY,tmeEnd) - CREATEDATETIME(TODAY,tmeStart);
    iElapsed := durElapsed;
    iRunTime := iElapsed/60000; 
    
    where do you thing the above code could be placed. Time in, time out entry form or the report or the time sheet table.
    Thanks.
  • jlandeenjlandeen Member Posts: 524
    I would put that code whereever you need to have the total elapsed time calculated - either the report or form that you're modifying.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • webweb Member Posts: 102
    i have placed it in both the form and the report but its not working. Here is my report maybe i am missing some logics:
    OBJECT Report 50012 Staff Attendance report
    {
      OBJECT-PROPERTIES
      {
        Date=14/03/08;
        Time=12:26:14;
        Modified=Yes;
        Version List=NAV01;
      }
      PROPERTIES
      {
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table50012;
            OnAfterGetRecord=BEGIN
                               //"Total Time" := "Total Time"/(60 * 60 * 1000);
                               durElapsed := CREATEDATETIME(TODAY,tmeEnd) - CREATEDATETIME(TODAY,tmeStart);
                               iElapsed := durElapsed;
                               iRunTime := iElapsed/60000;
                             END;
    
            ReqFilterFields=Employee No.,Date;
            TotalFields=Total Time;
            GroupTotalFields=Employee No.;
          }
          SECTIONS
          {
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18300;
                SectionHeight=1692;
              }
              CONTROLS
              {
                { 1000000001;Label  ;0    ;0    ;6150 ;423  ;FontSize=8;
                                                             FontBold=Yes;
                                                             CaptionML=ENU=Staff time sheet }
                { 1000000002;TextBox;15000;0    ;3150 ;423  ;HorzAlign=Right;
                                                             SourceExpr=FORMAT(TODAY,0,4) }
                { 1000000003;TextBox;0    ;423  ;6150 ;423  ;SourceExpr=COMPANYNAME }
                { 1000000004;TextBox;17700;423  ;450  ;423  ;CaptionML=ENU=Page;
                                                             SourceExpr=CurrReport.PAGENO }
                { 1000000005;Label  ;16950;423  ;750  ;423  ;ParentControl=1000000004 }
                { 1000000006;TextBox;15900;846  ;2250 ;423  ;HorzAlign=Right;
                                                             SourceExpr=USERID }
                { 1000000013;Label  ;6300 ;846  ;7200 ;423  ;HorzAlign=Center;
                                                             FontSize=10;
                                                             FontBold=Yes;
                                                             CaptionML=ENU=STAFF ATTENDANCE REPORT }
              }
               }
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18300;
                SectionHeight=1269;
              }
              CONTROLS
              {
                { 1000000009;Label  ;0    ;0    ;1500 ;846  ;ParentControl=1000000008;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 1000000012;Label  ;1650 ;0    ;4500 ;846  ;ParentControl=1000000011;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 1000000015;Label  ;6300 ;0    ;1500 ;846  ;ParentControl=1000000014;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 1000000018;Label  ;7950 ;0    ;1500 ;846  ;ParentControl=1000000017;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 1000000021;Label  ;9600 ;0    ;1800 ;846  ;ParentControl=1000000020;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 1000000024;Label  ;14100;0    ;1200 ;846  ;ParentControl=1000000023;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
              }
               }
            { PROPERTIES
              {
                SectionType=Body;
                SectionWidth=18300;
                SectionHeight=423;
              }
              CONTROLS
              {
                { 1000000008;TextBox;0    ;0    ;1500 ;423  ;HorzAlign=Left;
                                                             SourceExpr="Employee No." }
                { 1000000011;TextBox;1650 ;0    ;4500 ;423  ;HorzAlign=Left;
                                                             SourceExpr=Name }
                { 1000000014;TextBox;6300 ;0    ;1500 ;423  ;HorzAlign=Left;
                                                             SourceExpr="Time In" }
                { 1000000017;TextBox;7950 ;0    ;1500 ;423  ;HorzAlign=Left;
                                                             SourceExpr="Time Out" }
                { 1000000020;TextBox;9600 ;0    ;1800 ;423  ;HorzAlign=Right;
                                                             SourceExpr="Total Time" }
                { 1000000023;TextBox;14100;0    ;1350 ;423  ;HorzAlign=Left;
                                                             SourceExpr=Date }
                { 1000000016;TextBox;11550;0    ;1800 ;423  ;SourceExpr=iRunTime }
              }
               }
            { PROPERTIES
              {
                SectionType=GroupFooter;
                SectionWidth=18300;
                SectionHeight=846;
                OnPreSection=BEGIN
                               "Total Time" += "Total Time";
                             END;
    
              }
              CONTROLS
              {
                { 1000000000;TextBox;9600 ;0    ;1800 ;423  ;SourceExpr="Total Time" }
              }
               }
            { PROPERTIES
              {
                SectionType=Footer;
                SectionWidth=18300;
                SectionHeight=846;
              }
              CONTROLS
              {
                { 1000000007;TextBox;9000 ;0    ;2550 ;423  ;HorzAlign=Right;
                                                             FontSize=8;
                                                             FontBold=Yes;
                                                             SourceExpr="Total Time" }
                { 1000000010;Label  ;0    ;0    ;2250 ;423  ;FontSize=8;
                                                             FontBold=Yes;
                                                             CaptionML=ENU=Total Time }
              }
               }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          tmeStart@1000000000 : Time;
          tmeEnd@1000000004 : Time;
          durElapsed@1000000003 : Duration;
          iElapsed@1000000002 : BigInteger;
          iRunTime@1000000001 : Integer;
    
        BEGIN
        END.
      }
    }
    
    

    Any idea please?
Sign In or Register to comment.