Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9041201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:10:57+00:00 2026-06-16T10:10:57+00:00

my table has a column which formated in mysql time() format. when it’s one

  • 0

my table has a column which formated in mysql time() format.
when it’s one value assign into php variable called $preRemainOt
i want to re arrange it into nearest 15 minute

function roundTime($whatTime)
{

echo $whatTime."=>";

$roundTime= round ( strtotime($whatTime) / 60 * 15  );

echo date("H:i:s",$roundTime)."<br>";

return date("H:i:s",$roundTime);
}

    $validOt =roundTime($preRemainOt);

<pre>
few bad result given from my try as follow:
$preRemainOt=>$validO
    03:43:00=>06:55:45
    01:05:00=>06:16:15
    02:00:00=>06:30:00
but result shuld be as follow:
$preRemainOt=>$validO
    03:43:00=>03:45:00
    01:05:00=>01:00:00
    02:00:00=>02:00:00

1.pls give me an idea.
2.what happen if my remaining ot value($preRemainOt) exceed 24 hour
ex:$preRemainOt='26:43:00' is that doesn’t matter to either php or mysql function.
what is the best mysql data type to store such a ot calculation

update1
after few advices i spilt my function in to three section

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);
}

that because before the column value assigning into $preRemainOt variable ,there are another few steps.i change such two steps also,

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);
}

so i decided that it’s dificult to use select UNIX_TIMESTAMP(). it would be change my whole script.
in this case "%d:%02d:%02d" give nonsense

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:10:58+00:00Added an answer on June 16, 2026 at 10:10 am

    Try this:

    function roundTime($whatTime) {
        $time = strtotime($whatTime) + 450;
        return date("H:i:s", $time - $time % 900);
    }
    

    Edit:

    Actually, based on your comment below, here’s what I’d do. If this is a time interval and not a literal point in time, I would store the value in the database as an integer number of seconds instead of a DATETIME type. So 30:37:29 would be stored as 110249, since 110249 seconds is 30 hours, 37 minutes, and 29 seconds.

    Then instead of passing “30:37:29” to this function, you would past 110249. The function then would be:

    function roundTime($interval) {
        $interval = intval($interval) + 450;
        $interval -= $interval % 900;
        return sprintf("%d:%02d:%02d",
            intval($interval / 3600),       // hours
            intval($interval / 60) % 60,    // minutes
            $interval % 60);                // seconds
    }
    

    If you’ve already stored a bunch of stuff in the database and absolutely cannot convert it to seconds instead of DATETIMEs, then in your query, instead of querying the DATETIME, use the UNIX_TIMESTAMP function along with the function above. In other words, instead of this:

    SELECT id, name, preRemainOt, other_stuff...
    

    Do this:

    SELECT id, name, UNIX_TIMESTAMP(preRemainOt) AS preRemainOt, other_stuff...
    

    Then pass the integer value of that column to the roundTime function instead of the value of the DATETIME.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have a table Users that has only one column UserId which is
Suppose there is a table A which has a column AccessRights which is multivalued(
I have a table articles that has a column company which has list of
I have a table which has a column called Direct of type char(1). It's
We have a Oracle 9i database and OrderDetails table which has a column to
I have a table which has a NVARCHAR column, which could contain a GUID
I have a table called Event. A column has duration--which is...how long that event
I have a table in SQLite database of Android which has a column RANK
I currently have a table which only has a single editable column. I have
I have a table called scheduler_sched which has several columns, including a column called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.