Note that there are some explanatory texts on larger screens.

plurals
  1. POinto nearest 15 minute
    text
    copied!<p>my table has a column which formated in mysql <code>time()</code> format.<br> when it's one value assign into php variable called <code>$preRemainOt</code><br> i want to re arrange it into nearest 15 minute </p> <pre><code>function roundTime($whatTime) { echo $whatTime."=&gt;"; $roundTime= round ( strtotime($whatTime) / 60 * 15 ); echo date("H:i:s",$roundTime)."&lt;br&gt;"; return date("H:i:s",$roundTime); } $validOt =roundTime($preRemainOt); &lt;pre&gt; few bad result given from my try as follow: $preRemainOt=&gt;$validO 03:43:00=&gt;06:55:45 01:05:00=&gt;06:16:15 02:00:00=&gt;06:30:00 but result shuld be as follow: $preRemainOt=&gt;$validO 03:43:00=&gt;03:45:00 01:05:00=&gt;01:00:00 02:00:00=&gt;02:00:00 </code></pre> <p><br> 1.pls give me an idea.<br> 2.what happen if my remaining ot value(<code>$preRemainOt</code>) exceed 24 hour <code>ex:$preRemainOt='26:43:00'</code> is that doesn't matter to either php or mysql function.<br> what is the best mysql data type to store such a ot calculation</p> <p><strong>update1</strong><br> after few advices i spilt my function in to three section </p> <pre><code>function secondToTime($timeStamp) { $hours=intval($timeStamp / 3600); $mins=intval($timeStamp / 60) % 60; $secs=$timeStamp % 60; return sprintf("%d:%02d:%02d",$hours, $mins, $secs); } function timeToSecond($time='00:00:00') { list($hours, $mins, $secs) = explode(':', $time); $timeToSecond = ($hours * 3600 ) + ($mins * 60 ) + $secs; return $timeToSecond; } function roundTime($interval='00:00:00') { $interval=timeToSecond($interval); $interval = intval($interval) + 450; $interval -= $interval % 900; return secondToTime($interval); } </code></pre> <p>that because before the column value assigning into <code>$preRemainOt</code> variable ,there are another few steps.i change such two steps also,</p> <pre><code>function timeDiff($lastTime,$firstTime) { $firstTimetime=timeToSecond($firstTime); $lastTime=timeToSecond($lastTime); $timeDiff=$lastTime-$firstTime; return secondToTime($timeDiff); } function timeAdd($firstTime,$lastTime) { $firstTimetime=timeToSecond($firstTime); $lastTime=timeToSecond($lastTime); $timeAdd=2*$lastTime-$firstTime;; return secondToTime($timeAdd); } </code></pre> <p>so i decided that it's dificult to use select <code>UNIX_TIMESTAMP()</code>. it would be change my whole script. <strong>in this case <code>"%d:%02d:%02d"</code> give nonsense</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload