[英]PHP Timesheet calculate past 24hrs
I'm trying to calculate a timesheet i'm working on within a JS onChange event, the following works but it wont work past midnight, for example 23:00 - 01:00 returns 22 instead of 2 or rather 2.00 as I'd like it to report to 2 decimal places. 我正在尝试计算我正在JS onChange事件中处理的时间表,但可以正常工作,但无法在午夜后使用,例如23:00-01:00返回22而不是2或2.00,就像我想要的那样希望报告到小数点后2位。
$startm = date_create({mS}); //create a php datetime object
$finishm = date_create({mF});
$t_diff = date_diff($startm, $finishm); //calculate the difference
{mT} = $t_diff->h + round($t_diff->i/60,2) + {mOt} + {mOt2} /24; //add everything up
The form has the following fields 表单具有以下字段
Start Tme = mS - 24hr time
Finish Time = mF - 24hr time
Overtime = mOt - int
Overtime 2 = mOt2 - int
Total = mT - int
You can just add a check if $startm
is past noon and $finishm
is NOT past noon, $total -= 12
. 如果$startm
是中午之后,而$finishm
不是中午,您可以添加检查, $startm
$total -= 12
。 This of course won't work for shifts that last more than 24 hours, but that doesn't seem to be an acceptance criteria for your code. 当然,这对于持续超过24小时的班次无效,但是这似乎并不是代码接受的条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.