[英]how to get total no of working hours with date & time in MYSQL with reference to checkin & next day checkout time
[英]How to get total sum of hours for each day
我有一種情況,我需要計算每天每套的總工作時間。 但是我堅持了很多天。 我嘗試獲得如下輸出:
Day Clock In Clock Out Total Hours(Hr) Total Hours Per Day(Hr)
Monday 08:00 09:00 1.00
10:00 12:00 2.00
13:00 14:30 1.50 4.50
Tuesday 08:30 10:00 1.50
15:00 17:50 2.83 4.33
Wednesday 08:00 17:00 9.00 9.00
Total 17.83
到目前為止,我已經嘗試編寫代碼並做出了一些努力。 請幫助我。 會非常感激。
for($days=0;$days<3;$days++) { //get how many days
$clocked_records_each_day = count($get_attendance_records); //get attendance clock sets
for($records=0; $records<$clocked_records_each_day; $records++) {
$total_hour_per_set = $clocked_records_each_day[$records]['total_hour'];
$total_hour_per_day = ??;
$total_hour_overall = ??;
//stuck until here
//get the output and display
}
}
基本上:
/* Init grand total: */
$total_hour_overall = 0;
for($days=0;$days<3;$days++) { //get how many days
/* Init day subtotal at each for loop: */
$total_hour_per_day = 0;
$clocked_records_each_day = count($get_attendance_records); //get attendance clock sets
for($records=0; $records<$clocked_records_each_day; $records++) {
$total_hour_per_set = $clocked_records_each_day[$records]['total_hour'];
/* Increment day subtotal and grand total: */
$total_hour_per_day += $clocked_records_each_day[$records]['total_hour'];
$total_hour_overall += $clocked_records_each_day[$records]['total_hour'];
/* Echo set total inside records for: */
echo $total_hour_per_set;
}
/* Echo day subtotal inside days for: */
echo $total_hour_per_day;
}
/* Echo grand total outside for loop: */
echo $total_hour_overall;
您需要分兩部分進行操作,首先將其總和,然后顯示出來。
for($records=0; $records<$clocked_records_each_day; $records++) {
$total_hour_per_set = $clocked_records_each_day[$records]['total_hour'];
$total_hour_per_day[$clocked_records_each_day[$records]['day'][] = $total_hour_per_set
$total_hour_overall+= $total_hour_per_set;
}
因此,現在您擁有了所需的所有數據。
每天您都可以展示
for($records=0; $records<$clocked_records_each_day; $records++) {
Display( $total_hour_per_set = $clocked_records_each_day[$records]['total_hour']);
Display( array_sum( $total_hour_per_day[$clocked_records_each_day[$records]['day'] ) );
Display( $total_hour_overall+= $total_hour_per_set );
}
假定您具有Display(...)函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.