• Resolved Francis

    (@emolotel)


    I have to make a calculated field that gives me the hours in response. But how do I do the base 60 calculations instead of base 100

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @emolotel

    And your equation is?

    Best regards.

    Plugin Author codepeople

    (@codepeople)

    Hello @emolotel

    My apologies, I’m re-reading all opened questions, and I’ve understood now what do you need, I’m sorry.

    If you have a number that represent the number of minutes: X, and you want get the result as H hours and M minutes, you need to get the integer part of division X/60 for hours, and the rest of division X%60 as minutes.

    So, the process would be as follows:

    
    (function(){
    var h = FLOOR(fieldname1/60), m = fieldname1%60;
    return h+' hours and '+m+' minutes';
    })()
    

    In the piece of code above, I’m assuming the fieldname1 field includes the total of minutes you want to transform.

    Best regards.

    Hello
    I had the same problem, I try to add hours and minutes, I succeeded is in the base 100,, I wrote the code that you put in the comment above in the box of equation in Advanced equation’s editor but it doesn’t work unfortunately
    Could you help me solve the problem? to display and add the results in Hours and minutes?

    Plugin Author codepeople

    (@codepeople)

    Hello @adnanesa3d

    The process is simple, assuming you have A hours with B minutes, and X hours with Y minutes.

    and you want to sum both:

    * First, you should move everything to a same unit of measurement: minutes
    The first operand would be: C = A*60+B, and the second operands: Z = X*60+Y

    * Now, you can sum both operands in minutes: M = C+Z

    * Finally, with everything in minutes, you simply should transform it in hours and minutes:

    FLOOR(M/60)+’:’+(M % 60)

    and that’s all. It is simply mathematics.

    
    (function(){
        var A = fieldname1, 
            B = fieldname2, 
            X = fieldname3, 
            Y = fieldname4,
            C = A*60+B,
            Z = X*60+Y,
            M = C+Z;
    
        return FLOOR(M/60)+':'+(M % 60);
    })()
    

    Best regards.

    thanks for your quick reply, i really appreciate

    the problem I have is I don’t have a fieldname1 for the hours and another fieldname2 for the minutes, I have a fieldname which contains the hours and the minutes both at the same time.
    how can I solve this problem please ?to add two filednem which contains the hours and the minutes at the same time

    Thanks =)

    Plugin Author codepeople

    (@codepeople)

    Hello @adnanesa3d

    The process is simple, you only should to use the same CDATE operation to extract the time components(hh for hours, and ii for minutes).

    Assuming you have only two date/time fields only with the time components enabled: fieldname1 and fieldname2, the equation would be:

    
    (function(){
        var A = CDATE(fieldname1,'hh')*1, 
            B = CDATE(fieldname1,'ii')*1, 
            X = CDATE(fieldname2,'hh')*1, 
            Y = CDATE(fieldname2,'ii')*1, 
            C = A*60+B,
            Z = X*60+Y,
            M = C+Z;
    
        return FLOOR(M/60)+':'+(M % 60);
    })()
    

    Best regards.

    Hello
    I really appreciate your help, the solution that you have indicated works very well, thank you very much but I have a little problem whenI try to do subtraction of hours the displayed result is not always correct :
    For example if I try to make this calculation 22h23 – 20h20 the displayed result is 2h3 min and is not 2h03 min otherwise for the other calculations there is no problem

    Thanks =)

    how i can solve this issue please =) .

    Plugin Author codepeople

    (@codepeople)

    Hello @adnanesa3d

    I have sent you different alternatives for different data structure, but you never describe your data structure. If you have two text fields with the structure: XXhYY where X and Y are digits, evidently you should to manage the value as a text and extract the digits:

    
    (function(){
        var A = fieldname1.split(/h/g)[0]*1, 
            B = fieldname1.split(/h/g)[1]*1, 
            X = fieldname2.split(/h/g)[0]*1, 
            Y = fieldname2.split(/h/g)[1]*1, 
            C = A*60+B,
            Z = X*60+Y,
            M = C+Z;
    
        return FLOOR(M/60)+':'+(M % 60);
    })()
    

    I’m sorry, but the support service does not cover the implementation of the users’ projects (forms or formulas). If you need additional support you should contact us through our private website: Customization

    Best regards.

    Hello
    first of all I want to thank you for your enormous support, I really appreciate, you are right I did not specify my data structure, I explain my data structure and the display problem that I have:
    -I have 2 fieldname (Fieldname1 and Fieldname2) each fildname indicates an hour with the minutes example: fildename1 XXHYY and fildename2 AAHBB
    I try to do subtraction hours (faildname 2 – fildename 1) I used the following program that you wrote:
    (function () {
    ????var A = CDATE (fieldname1, ‘hh’) * 1,
    ????????B = CDATE (fieldname1, ‘ii’) * 1,
    ????????X = CDATE (fieldname2, ‘hh’) * 1,
    ????????Y = CDATE (fieldname2, ‘ii’) * 1,
    ????????C = A * 60 + B,
    ????????Z = X * 60 + Y,
    ????????M = C-Z;

    ????return FLOOR (M / 60) + ‘:’ + (M% 60);
    }) ()
    ?the code at the top works very well, but there is a small problem is that the result between 0-9 for minutes, it is displayed like this 9 instead of 09 Mintues
    I give you an example if I try to do this calucl with the code above: 12h23-10h20 = 2h3 instead of displaying 02h03, on the other hand for this kind of calculation the code works very well: 23h44-15h23 = 8h21 there is no problem.
    I’m not trying to modify or customize the calculator I’m just trying to solve the display problem that I explained above
    Thank you for your understanding

    Plugin Author codepeople

    (@codepeople)

    Hello @adnanesa3d

    If your date structure is a text with the format: XXHMM, you should use the last variant (that uses the split method), but if you are not sure if the separator is h or H, modify the regular expression to split the values as follows:

    
    A = fieldname1.split(/h/i)[0]*1, 
    B = fieldname1.split(/h/i)[1]*1, 
    

    If you want the output with two digits, edit the following piece of code:

    
    return FLOOR(M/60)+':'+(M % 60);
    

    as follows:

    
    var final_hours = FLOOR(M/60),  final_minutes = (M % 60);
    if(final_hours < 10) final_hours = '0'+final_hours;
    if(final_minutes < 10) final_minutes = '0'+final_minutes;
    
    return final_hours+':'+final_minutes;
    

    Best regards.

    thanks a lot
    problem is solved
    thank you for your huge support

    Best regards

    • This reply was modified 4 years, 10 months ago by adnanesa3d.
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘calculate hours’ is closed to new replies.