我在PHP中有一个函数,它以下列格式返回postgresql数据库所用的时间
00:34:01.024416
在php中,这些数据存储为" String"这没什么用。我可以在PHP中使用什么,以便我可以对数据库提供的数据进行计算?
答案 0 :(得分:0)
您可以将postgres中的数据转换为毫秒或微秒。这可以存储在PHP中,以后用于操作总时间......如下所示的查询将帮助您完成此操作
SELECT
(EXTRACT (HOURS FROM TIME '00:34:01.024416') * 3600000) :: int AS "hour-millisecond",
(EXTRACT (MINUTE FROM TIME '00:34:01.024416') * 60000) :: int AS "minute-millisecond",
(EXTRACT (SECOND FROM TIME '00:34:01.024416') * 1000) :: int AS "second-millisecond",
(EXTRACT (MILLISECONDS FROM TIME '00:34:01.024416')) :: int AS "millisecond"
SELECT (EXTRACT (HOURS FROM TIME '00:34:01.024416') * 3600000) :: int +
(EXTRACT (MINUTE FROM TIME '00:34:01.024416') * 60000) :: int +
(EXTRACT (SECOND FROM TIME '00:34:01.024416') * 1000) :: int +
(EXTRACT (MILLISECONDS FROM TIME '00:34:01.024416')) :: int AS millisecondelapsed
[编辑]
SELECT (EXTRACT (HOURS FROM elapsedtime_result.elapsedtime) * 3600000) :: int +
(EXTRACT (MINUTE FROM elapsedtime_result.elapsedtime) * 60000) :: int +
(EXTRACT (SECOND FROM elapsedtime_result.elapsedtime) * 1000) :: int +
(EXTRACT (MILLISECONDS FROM elapsedtime_result.elapsedtime)) :: int AS millisecondelapsed
FROM (SELECT current_timestamp - max(createdon) elapsedtime FROM testtable) AS elapsedtime_result