Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Labor Hours between 2 dates.
csasaki
Hi I need to calculate the labor hours between 2 dates.
For example :
Labor Schedule : 8:00 AM - 5:00 PM Monday to Friday
Monday 2 January 2012 - 1:00 PM
Monday 9 January 2012 - 2:00 PM
Labor Hours between dates : 41 Hours
Or
Monday 2 January 2012 - 2:00 PM
Tuesday 3 January 2012 - 9:00 AM
Labor Hours between dates : 4 Hours.
I have the 2 dates (timestamp) and need the hours between them.
Any idea?
Find more posts tagged with
Comments
csasaki
Well
I finally got a logic for this.
1) Get the labor days between the 2 dates. (Checked)
2) Subtract 2 days to the labor days. (Checked)
3) Multiply the labor days left for 8hours a day. (Checked)
4) Get the hour of the first date and use the BirtDateTimeDiffMinute function to get the minutes between the first date hour and 5pm.
5) Get the hour of the last date and use the BirtDateTimediffMinute function to get the minutes between the last date hour and 8AM.
mwilliams
So, problem solved?
csasaki
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="93812" data-time="1326127649" data-date="09 January 2012 - 09:47 AM"><p>
So, problem solved?<br /></p></blockquote>
<br />
Hi Michael<br />
<br />
I could not get the report done.<br />
But Again I would like to calculate the labor hours between 2 dates. Also not including the Weekends days. Do you have any logic I could use?<br />
<br />
I was thinking on calculate the weeks between the 2 dates. Then multiply those week_numbers * 2 to get the Weekends. But not sure.
lgudait
I came up with a solution that makes the following assumptions:
- Start & End dates are always weekdays within working hours
- Workdays are always 8 hours, starting at 9:00 AM
- No consideration is given to breaks/lunches, nor company holidays
I designed the solution using 2 parameters (StartDate & EndDate) - substitute whatever your fields are for the parameters
+BirtDateTime.diffDay(params["StartDate"].value,params["EndDate"].value)*8
-(BirtDateTime.week(params["EndDate"].value)-BirtDateTime.week(params["StartDate"].value))*16
-(params["StartDate"].value.getHours()-9)
+(params["EndDate"].value.getHours()-9)
Line 1 calculates the total potential work hours between the start & end date
Line 2 removes any hours that fall over the weekend.
Line 3 accounts for any start times after 9 AM on the first day
Line 4 adds in any hours on the last day
lgudait
One more restriction that I didn't realize when I posted - Line 2 assumes that it is the same year. I made a small modification that accounts for multiple years:
+BirtDateTime.diffDay(params["StartDate"].value,params["EndDate"].value)*8
-(BirtDateTime.diffWeek(params["StartDate"].value,params["EndDate"].value))*16
-(params["StartDate"].value.getHours()-9)
+(params["EndDate"].value.getHours()-9)
csasaki
<blockquote class='ipsBlockquote' data-author="'lgudait'" data-cid="109461" data-time="1347915384" data-date="17 September 2012 - 01:56 PM"><p>
One more restriction that I didn't realize when I posted - Line 2 assumes that it is the same year. I made a small modification that accounts for multiple years:<br />
<br />
+BirtDateTime.diffDay(params["StartDate"].value,params["EndDate"].value)*8<br />
-(BirtDateTime.diffWeek(params["StartDate"].value,params["EndDate"].value))*16<br />
-(params["StartDate"].value.getHours()-9)<br />
+(params["EndDate"].value.getHours()-9)<br /></p></blockquote>
<br />
Hi<br />
<br />
Thanks for your reply. What you did was very simple and good!hat will you add to your code to get the minutes also? <br />
<br />
<br />
My code is to large :<br />
<br />
<br />
var weeks = BirtDateTime.diffWeek(params["Date1 1"].value,params["Fecha 2"].value);<br />
var days = BirtDateTime.diffDay(params["Date2 1"].value,params["Fecha 2"].value);<br />
var days_completes = (days - weeks*2 - 1);<br />
<br />
var Fecha_param_1 = params["Date1 1"].value;<br />
var Fecha_param_2 = params["Date2 2"].value;<br />
if (Fecha_param_2== null)<br />
{<br />
Fecha_param_2 =BirtDateTime.now();<br />
}<br />
if (dias_completos >= 0) <br />
{<br />
var Year1= BirtDateTime.year(params["Fecha 1"].value);<br />
var Mes1 =BirtDateTime.month(params["Fecha 1"].value);<br />
var day1 = BirtDateTime.day(params["Fecha 1"].value);<br />
var fecha1 = Year1 + "-" + Mes1 + "-" + day1 +" 18:00:00" ;<br />
var minutos_dia1 = BirtDateTime.diffMinute(params["Fecha 1"].value,fecha1);<br />
<br />
var Year2= BirtDateTime.year(Fecha_param_2);<br />
var Mes2 =BirtDateTime.month(Fecha_param_2);<br />
var day2 = BirtDateTime.day(Fecha_param_2);<br />
var fecha2 = Year2 + "-" + Mes2 + "-" + day2 +" 09:00:00" ;<br />
var minutos_dia2 = BirtDateTime.diffMinute(fecha2,Fecha_param_2);<br />
<br />
<br />
<br />
var minutos_total = dias_completos*60*9 + minutos_dia1 + minutos_dia2;<br />
<br />
<br />
var horas_total;<br />
horas_total = BirtMath.round(minutos_total/60,0);<br />
if (horas_total < 1)<br />
{ <br />
horas_total = 0;<br />
}<br />
<br />
var sobrante = BirtMath.mod(minutos_total,60);<br />
<br />
if (sobrante>=10)<br />
{<br />
var output = horas_total + ":" + sobrante;<br />
}<br />
else <br />
{<br />
var output = horas_total +":0" +sobrante;<br />
}<br />
output;<br />
<br />
}<br />
<br />
if (dias_completos == -1) <br />
{<br />
<br />
var minutos_total=BirtDateTime.diffMinute(params["Fecha 1"].value,Fecha_param_2);<br />
<br />
var horas_total;<br />
horas_total = BirtMath.round(minutos_total/60,0);<br />
if (horas_total < 1)<br />
{ <br />
horas_total = 0;<br />
}<br />
var sobrante = BirtMath.mod(minutos_total,60);<br />
<br />
if (sobrante>=10)<br />
{<br />
var output = horas_total + ":" + sobrante;<br />
}<br />
else <br />
{<br />
var output = horas_total +":0" +sobrante;<br />
}<br />
output;<br />
<br />
}
Panky
Igudait, that works perfectly thanks. A sweet and simple solution<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'csasaki'" data-cid="109469" data-time="1347917693" data-date="17 September 2012 - 02:34 PM"><p>
Hi<br />
<br />
Thanks for your reply. What you did was very simple and good!hat will you add to your code to get the minutes also? <br />
<br />
<br />
My code is to large :<br />
<br />
<br />
var weeks = BirtDateTime.diffWeek(params["Date1 1"].value,params["Fecha 2"].value);<br />
var days = BirtDateTime.diffDay(params["Date2 1"].value,params["Fecha 2"].value);<br />
var days_completes = (days - weeks*2 - 1);<br />
<br />
var Fecha_param_1 = params["Date1 1"].value;<br />
var Fecha_param_2 = params["Date2 2"].value;<br />
if (Fecha_param_2== null)<br />
{<br />
Fecha_param_2 =BirtDateTime.now();<br />
}<br />
if (dias_completos >= 0) <br />
{<br />
var Year1= BirtDateTime.year(params["Fecha 1"].value);<br />
var Mes1 =BirtDateTime.month(params["Fecha 1"].value);<br />
var day1 = BirtDateTime.day(params["Fecha 1"].value);<br />
var fecha1 = Year1 + "-" + Mes1 + "-" + day1 +" 18:00:00" ;<br />
var minutos_dia1 = BirtDateTime.diffMinute(params["Fecha 1"].value,fecha1);<br />
<br />
var Year2= BirtDateTime.year(Fecha_param_2);<br />
var Mes2 =BirtDateTime.month(Fecha_param_2);<br />
var day2 = BirtDateTime.day(Fecha_param_2);<br />
var fecha2 = Year2 + "-" + Mes2 + "-" + day2 +" 09:00:00" ;<br />
var minutos_dia2 = BirtDateTime.diffMinute(fecha2,Fecha_param_2);<br />
<br />
<br />
<br />
var minutos_total = dias_completos*60*9 + minutos_dia1 + minutos_dia2;<br />
<br />
<br />
var horas_total;<br />
horas_total = BirtMath.round(minutos_total/60,0);<br />
if (horas_total < 1)<br />
{ <br />
horas_total = 0;<br />
}<br />
<br />
var sobrante = BirtMath.mod(minutos_total,60);<br />
<br />
if (sobrante>=10)<br />
{<br />
var output = horas_total + ":" + sobrante;<br />
}<br />
else <br />
{<br />
var output = horas_total +":0" +sobrante;<br />
}<br />
output;<br />
<br />
}<br />
<br />
if (dias_completos == -1) <br />
{<br />
<br />
var minutos_total=BirtDateTime.diffMinute(params["Fecha 1"].value,Fecha_param_2);<br />
<br />
var horas_total;<br />
horas_total = BirtMath.round(minutos_total/60,0);<br />
if (horas_total < 1)<br />
{ <br />
horas_total = 0;<br />
}<br />
var sobrante = BirtMath.mod(minutos_total,60);<br />
<br />
if (sobrante>=10)<br />
{<br />
var output = horas_total + ":" + sobrante;<br />
}<br />
else <br />
{<br />
var output = horas_total +":0" +sobrante;<br />
}<br />
output;<br />
<br />
}<br /></p></blockquote>