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)
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 =)