gpt4 book ai didi

php - 使用 MySQL 查询在 PHP 中计算时间

转载 作者:行者123 更新时间:2023-11-29 23:15:56 26 4
gpt4 key购买 nike

我有一个用 PHP 构建的报告,其中我需要时差乘以小时费率来计算员工工资。

例如:

Employee     Clock-In           Clock-Out     Total-Hours  Rate  Salary
Mike 2015-01-01 22:57:09 2015-01-02 11:48:14 12:51:05 10 128.51
Mike 2015-01-03 11:48:51 2015-01-06 22:19:27 82:30:36 10 825.10
Mike 2015-01-06 21:19:40 2015-01-06 22:00:00 00:40:20 10 6.72

我的查询如下

SELECT tt.id,ts.fname,tt.punch_in,tt.punch_out,
SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)) as working_hours_new,ter.hourlyrate,
((SUBSTRING(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)),1,2) + SUBSTRING(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)),4,2)/60 + SUBSTRING(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)),7,2)/3600) * ter.hourlyrate) as pay
from tbl_times as tt left join tbl_server as ts on ts.serverid = tt.user_id left join tbl_employee_rates as ter on ter.userid=tt.user_id
where ts.locationid = ? and ts.active = 1 and ter.stauts = 1 and date(punch_in) >= ? and date(punch_out) <= ?

如果这不是一个简单的方法,我应该用 PHP 来做吗...有什么建议吗?

最佳答案

为什么不尝试:(假设mysql)

((UNIX_TIMESTAMP(tt.punch_out) - UNIX_TIMESTAMP(tt.punch_in)) / 3600) * ter.hourlyrate AS salary

关于php - 使用 MySQL 查询在 PHP 中计算时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27809807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com