简体   繁体   English

以小时和分钟为单位计算总时间值

[英]Calculate Total Time Value in Hours & Minutes

I have an input form where the user will input their start time and their start time. 我有一个输入表单,用户可以在其中输入他们的开始时间和开始时间。 I then have a function that calculates the time difference and stores the hours and minutes worked in a new field. 然后,我有了一个计算时差并在新字段中存储工作小时和分钟的函数。

What I want to do is calculate the total time as one value in Hours and Minutes. 我想做的是将总时间计算为“小时和分钟”中的一个值。

The following SQL will bring all the meta_value stored in the database 下面的SQL将把所有存储在数据库中的meta_value

SELECT wp_frm_item_metas.meta_value
FROM wp_frm_item_metas
WHERE 1=1 
   AND wp_frm_item_metas.field_id = '103'

This returns values as follows (first 5 only) 返回的值如下(仅前5个)

meta_value meta_value

2:15
1:15
2:15
4:15
0.00

If I use the following 如果我使用以下

SELECT SUM(wp_frm_item_metas.meta_value) AS total_hours
FROM wp_frm_item_metas
WHERE 1=1 
   AND wp_frm_item_metas.field_id = '103'

I do not get the total in hours and minutes so I wonder if anyone could help me to achieve this please? 我没有得到小时和分钟的总数,所以我想知道是否有人可以帮助我实现这一目标?

Thanks 谢谢

Wayne 韦恩

Use TIME_TO_SEC to convert to seconds, then SUM. 使用TIME_TO_SEC转换为秒,然后转换为SUM。 For output you could use SEC_TO_TIME function to get hours:mins. 对于输出,您可以使用SEC_TO_TIME函数获取小时:分钟。 Eg: 例如:

SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(wp_frm_item_metas.meta_value))) AS total_hours
   FROM wp_frm_item_metas
WHERE 1=1 
   AND wp_frm_item_metas.field_id = '103'

I haven't tested the above but should get you close... 我没有测试以上内容,但应该让您接近...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM