• Resolved f0u

    (@f0u)


    Want some help as I can’t figure it out myself.

    Want to create a time report to be able to calculate compensation based on time.
    A field with check-in date / time
    A field with check-out date / time
    Comments filed

    I want it to report total time in hours and minutes between those dates / times.
    I also want it to report the number of hours and minutes that occurred between 18:00 to 06:00 during the reported time from those fields.

    Is this even possible?

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

    (@codepeople)

    Hello @f0u

    I’ll try to describe the process with a hypothetical example

    Assuming you are using the free version of the plugin, and the date/time fields in the form are the fieldname1 and fieldname2.

    Insert a calculated field in form with the equation:

    
    (function(){
        var from = new Date(MIN(fieldname1,fieldname2)*86400000),
            to = new Date(MAX(fieldname1,fieldname2)*86400000),
            minutes = 0,
            special_minutes = 0;
    
        while(from < to)
        {
            minutes += 1;
            if(18*60<=minutes || minutes<6*60) special_minutes += 1;
            from.setMinutes(from.getMinutes()+1);
        }
        
        return FLOOR(minutes/60)+' hours and '+(minutes%60)+' hours, of them there are '+FLOOR(special_minutes/60)+' hours and '+(special_minutes%60)+' minutes between the 18:00 and 6:00 hours';
    })()
    

    If you need additional help with your personal project, you should contact us through our website: Contact Us

    Best regards.

    Thread Starter f0u

    (@f0u)

    Damn! It was quickly answered =) Big thanks!

    Very neat solution. But immediately got some follow-up questions.
    Probably I’ll solve the questions myself with your perfect example.

    1. Report in two separate fields. One field for total time and the other field with time that is between 18.00 and 06.00. ?

    2. Is it possible to save the values posted by this to a mysql database in one of the pay versions ?.

    I thought it was possible to present the data in a filterable table for later use. (maybe wpdatatable is usable, atleast it can read values from mysql db)

    Plugin Author codepeople

    (@codepeople)

    Hello @f0u

    The answer to the first question is simple. Assuming there is a fourth field (the fieldname5) where you want to display the second part of the previous answer. To avoid repeating the equation in two separated fields you can use the getField operation as part of the previous equation, to get the object representation of the fourth field, and call its setVal method.

    
    (function(){
        var from = new Date(MIN(fieldname1,fieldname2)*86400000),
            to = new Date(MAX(fieldname1,fieldname2)*86400000),
            minutes = 0,
            special_minutes = 0;
    
        while(from < to)
        {
            minutes += 1;
            if(18*60<=minutes || minutes<6*60) special_minutes += 1;
            from.setMinutes(from.getMinutes()+1);
        }
        getField(5).setVal(FLOOR(special_minutes/60)+' hours and '+(special_minutes%60)+' minutes between the 18:00 and 6:00 hours');
        return FLOOR(minutes/60)+' hours and '+(minutes%60)+' hours';
    })()
    

    Concerning to the second question, we’d like to help but we can’t reply about that in this forum. We are not allowed to support any customers in these forums.

    For pro or commercial product support please contact us directly on our site. This includes any pre-sales topics as well.

    Commercial products are not supported in these forums. We will happily answer this and any other questions you can have on our own site.

    Thank you.

    Thread Starter f0u

    (@f0u)

    Big thanks.
    Will contact you =)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Would this be possible?’ is closed to new replies.