i have some data which is coming as: 0.00000 37.17...
# lucee
g
i have some data which is coming as: 0.00000 37.17000 60.00000 60.00000 34.47000 now i am trying to get the time as how many minutes and seconds, so i am seeing it 194.04, i tried with mysql and with coldfusion both but i am always ending up with 194:11 my mysql solution is
Copy code
SELECT
    CONCAT(
        FLOOR(total_seconds / 60),
        ':',
        LPAD(MOD(total_seconds, 60), 2, '0')
    ) AS total_time
FROM (
    SELECT
        SUM(
            CAST(SUBSTRING_INDEX(mind, ':', 1) AS UNSIGNED) * 60 +
            CAST(SUBSTRING_INDEX(mind, ':', -1) AS UNSIGNED)
        ) AS total_seconds
    FROM
        stats
    WHERE
        ID IN (174)
) AS subquery;
my cf solution its totally wrong https://trycf.com/gist/6963fed15361103dc8780febec71c0a3/lucee5?theme=monokai
t
It is this line in your function
var seconds = val("0." & parts[2]) * 60;
By the look of your question and your SQL, you're treating the 2nd part of your data as the second itself But in your function you are making them as decimal and then multiply them by 60 So 0.17 should be 17 seconds, but you are doing 0.17 * 60 (so you are treating 0.17 as 0.17 minute, not 17 seconds) Change it to multiply by 100 should fix it Or just
var seconds = val( parts[2] );
g
and same with sql
i did the change https://trycf.com/gist/822205e0161655f09697d67d0df2b3f4/lucee5?theme=monokai but it still shows .38 instead of .04
this is close but but it is not returning what i expected it to be https://trycf.com/gist/5be61d10ef1ca2742116825f6c9a83a1/lucee5?theme=monokai
e
I maybe lacking coffee, but your last gist you have seconds multiplied by 100, plus you are treating strings as numbers, which I am very guilty of, but its not the greatest. Try this instead: https://trycf.com/gist/76c67b824f8a30d8e4fb92a09ba6ab19/lucee5?theme=monokai
g
answer should be 192.04 but the answer i am seeing with your gist is: 64191.00
e
I was under the impression that is what you where trying to do, but it looks like there is a conversion issue. Grabbing the seconds value without doing a massive conversion appears to work.
g
odd part i was not understanding why it was not splitting 64 into 60 + 4 as extra seconds
i am doing same in mysql now, but mysql suffers same issue
e
It's a low-level code of logic where time units range from 0 to 60. 😕
g
in mysql, i was able to reach 191.38, not sure it suffers same fate, even not sure if yyou are good in mysql, if yes, you can help me out else no worries