让我们说
工作人员的工作时间为2016-12-31 23:30 PM至2017-01-01 06:30 AM。
在这里,我需要根据以下规则计算总工资率:
Rule# | Date | StartTime | EndTime | WageRate(HR)
1 | 2016-12-31 | 07:00 | 23:59 | 25
2 | 2017-01-01 | 00:00 | 06:00 | 40
3 | 2017-01-01 | 06:00 | 11:30 | 30
答案 0 :(得分:1)
以下内容适用于PHP。我以一个虚拟阵列为例。
ProcessAndsend(Format *out, // IN
char const *reqp, // IN
size_t reqLen, // IN
Bool *Status, // OUT
char const **reply, // OUT
size_t *resLen) // OUT
<强>输出:强>
$arr = [
['Date'=>'2016-12-31', 'StartTime' => '07:00', 'EndTime' => '23:59', 'Rate' => 25],
['Date'=>'2017-01-01', 'StartTime' => '00:00', 'EndTime' => '06:00', 'Rate' => 40],
['Date'=>'2017-01-01', 'StartTime' => '06:00', 'EndTime' => '11:30', 'Rate' => 30]
];
function salaryCalc($start, $end, $rate) {
$timeStart = strtotime($start);
$timeEnd = strtotime($end);
$diff = $timeEnd - $timeStart;
$diffHours = round(($diff/60)/60); //I'm guessing you will pay them for the hour
return $diffHours * $rate;
}
foreach($arr as $v) {
echo 'Wage: ' . salaryCalc($v['StartTime'], $v['EndTime'], $v['Rate']);
echo '<br>';
}
编辑:
我全都是为了帮助别人,但自从你上次澄清你的问题以来,我似乎很清楚你甚至没有打算自己解决这个问题,所以直到你提供一些代码向我展示和别人的努力,我出去了。
答案 1 :(得分:0)
尝试此查询
select Rule,Date,StartTime,Endtime,WageRate,
-1 * timediff(StartTime,EndTime) * Wagerate as total
from hr;
如果您根据小时计算
答案 2 :(得分:-1)
结果如下:
On 2016-12-31
23:30- 23:59. =29 min rate can be taken from rule #1
On 2017-01-01
00:00 - 06:00 = 6hr rate apply from rule #2
06:00 - 06:30. =30min rate apply from rule #3